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.