0

Can someone please help me. My mind is not working as I have been debugging this for over a day now and my brain is dead. Need to wrap up this project soon as I have a code freeze coming up and this is not working :(

I am trying to call the service but I am getting an exception in task.Wait. What is wrong with it? I am unable to figure out what the issue is.
Please help.

Here's the config binding:

  <startup>
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="mssqllocaldb" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BillingSummaryAPISoap11Binding">
        <security mode="Transport" />
      </binding>
      <!--<binding name="BillingSummaryAPISoap11Binding1" />-->
    </basicHttpBinding>
    <customBinding>
       <binding name="BillingSummaryAPISoap12Binding">
         <textMessageEncoding messageVersion="Soap12" />
         <httpsTransport />
       </binding>
    </customBinding>
    <wsHttpBinding>
      <binding name="WSHttpBinding_IEmailService" messageEncoding="Mtom">
        <security mode="Transport" />
      </binding>
    </wsHttpBinding>
    </bindings>
    <client>
     <endpoint address="https://vldv/EmailService.svc"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmailService"
      contract="EmailService.IEmailService" name="WSHttpBinding_IEmailService" />
     <endpoint address="https://vldev3.ww.com/bc/ws/gw/webservice/BillingSummaryAPI"
      binding="customBinding" bindingConfiguration="BillingSummaryAPISoap12Binding"
      contract="BillingService.BillingSummaryAPIPortType" name="BillingSummaryAPISoap12Port"/>
    </client>
  </system.serviceModel>

Here's the call to the BillingSummaryAPI:

public static Dictionary<string, double> CallPolServiceForData()
{
    Dictionary<Int32, BResponse> pCallResponse = new Dictionary<int, BResponse>();
    Dictionary<Int32, DateTime> pcCallResponseTime = new Dictionary<int, DateTime>();
    Dictionary<string, double> pcCallResponseTimeDetails = new Dictionary<string, double>();
    List<int?> cancelledPolicies = GetCancelledPoliciesData();
    if (cancelledPolicies != null)
    {
        foreach (var item in cancelledPolicies)
        {
            if (item != null)
            {
                int policyNumber = Convert.ToInt32(item);
                string consoleInfo = policyNumber.ToString(); // to print on console

                pCallResponse.Add(policyNumber, null);

                BillingSummaryAPIPortTypeClient client = new BillingSummaryAPIPortTypeClient();
                authentication auth = new authentication();
                gw_locale l = new gw_locale();
                l.Value = "en_US";
                auth.username = ConfigurationManager.AppSettings["User"];
                auth.password = ConfigurationManager.AppSettings["Pass"];
                PolicyInfo info = new PolicyInfo();
                info.PolicyNumber = policyNumber.ToString();
                try
                {
                    pcCallResponseTime.Add(policyNumber, DateTime.Now);
                    var task = GetResponse(client, auth, l, info);

                    task.Wait();
                    var response = task.Result.@return;
                    pcCallResponseTimeDetails[response.PolicyNumber] = DateTime.
                        Now.Subtract(pcCallResponseTime[policyNumber]).TotalSeconds;
                    pCallResponse[policyNumber] = new BResponse()
                    {
                        OutStandingAmount = response.OutstandingAmount,
                        CancellationDate = response.CancellationDate,
                        ExpirationDate=response.ExpirationDate,
                    };
                    consoleInfo = consoleInfo + " Success";
                    Console.WriteLine(consoleInfo);

                }
                catch (Exception ex)
                {
                    pcCallResponseTimeDetails[policyNumber.ToString()] = DateTime.
                        Now.Subtract(pcCallResponseTime[policyNumber]).TotalSeconds;
                    pCallResponse[policyNumber] = new BResponse()
                    {
                        ErrorDesc = (ex.InnerException != null) ?
                            ex.InnerException.Message : ex.ToString()
                    };
                    consoleInfo = consoleInfo + " Error - " + pCallResponse[policyNumber].ErrorDesc;
                    Console.WriteLine(consoleInfo);
                }
            }
        }
        SaveResultToStg(pCallResponse);
    }
    return pcCallResponseTimeDetails;
}

However I update it either fails at the BillingSummaryAPIPortTypeClient() or at the task.Wait(); I have not made any changes to the code and it used to work fine earlier.

I see this exception now:

ex.InnerException.Message:

An error occurred while receiving the HTTP response to..... This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

StackTrace:

   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at BillingServiceAPICall.Program.CallPolServiceForData() in C:\VSCollection\POS\Rel_2022_11\Source\BillingServiceAPICall\Program.cs:line 79 

The underlying connection was closed: An unexpected error occurred on a receive.

I am stuck and unable to proceed further. Appreciate any feedback or input. Thank you.

Ditty
  • 521
  • 7
  • 24
  • Is the email account still operational? Did email server change requirements like port number? Is there a new version of the email API? – jdweng Aug 18 '22 at 02:52
  • @jdweng The issue is not in the Email Service. It's the BillingServiceAPI that's not working. When I put the URL I can see the WSDL. – Ditty Aug 18 '22 at 02:56
  • Does this answer your question? [This could be due to the service endpoint binding not using the HTTP protocol](https://stackoverflow.com/questions/5870958/this-could-be-due-to-the-service-endpoint-binding-not-using-the-http-protocol) Long story short: check the bindings. – Bartosz Olchowik Aug 18 '22 at 07:21
  • The configuration file has WSHttpBinding_IEmailService. So I think the Billing Service is connecting to an email server and the failure is the connection from the Bill Service to the Email Service. – jdweng Aug 18 '22 at 09:06
  • @BartoszOlchowik I checked that. And it is using the correct http protocol. – Ditty Aug 18 '22 at 15:33
  • @Ditty have you read this answer? https://stackoverflow.com/a/14481750/3837961 That answer actually might be helpfull, and this might be what is happening at your application (thats why i said- check bindings). Sorry if i was unclear. – Bartosz Olchowik Aug 18 '22 at 15:57
  • @BartoszOlchowik but I am just consuming that service. I have no way to access the service logs. – Ditty Aug 18 '22 at 17:36

0 Answers0