1

I'm able to query web service in ActionMethod of the controller, but unable to query it at the Application Startup.

Problem Description: I'm developing a WebApplication on ASP.net MVC 5, It makes use of data retrieved from a SOAP web service Autotask API. Let me just say it here, there are some records that have to be loaded/cached from the API before a user could do other operations.

So for communication between WebApp & Webservice,

  • I added a Service Reference with provided WSDL.
  • Created proxy class from it and while developing I've been calling Webservice in Controller's ActionMethods.
  • So in the View anytime user click a given link, a call to the Webservice is made. the retrieved list of records is cached within the app so that next time we won't have to make another call to Webservice. It's working fine.

What I'm trying to Achieve

In production, it'd be ideal to load these records at the application startup.

So I moved the call to Webservice from controller's ActionMethod to Application_Start() method in Global.asax.cs.

But When I start the app and at the time of querying data from Webservice. It results in error

The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

As I'm expecting records of data in XML format, Server returns with error The remote server returned an error: (500) Internal Server Error. stating the 'Username & Password is incorrect'

But I believe that's not the actual case. Because of two solid reasons

  1. I'm successfully connecting to Webservice using same credentials in the Controller's ActionMethod, as described above.
  2. Because of the following exceptions.

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory1 factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Also having an Inner Exception.

at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

To me, it shows that request timeout is being expired. I tried modifying the binding configuration to following, As explained in here WCF Service, How to increase the timeout?

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ATWS15" />
    <binding name="IncreasedTimeout" sendTimeout="00:10:00"></binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://webservices.address.toApi.net/atws.asmx"
    binding="basicHttpBinding" bindingConfiguration="IncreasedTimeout" contract="AutoTaskProxy.ATWS15"
     />
</client>

If anyone can help me, what am I doing wrong here.? I'm able to query webservice in ActionMethod of the controller, but unable to query it at the Application Startup

AlphaTry
  • 475
  • 5
  • 27

1 Answers1

0

You have response timeout exception, try to increase receiveTimeout

<bindings>
  <basicHttpBinding>
    <binding name="ATWS15" />
    <binding name="IncreasedTimeout" sendTimeout="00:10:00" receiveTimeout="00:10:00"></binding>
  </basicHttpBinding>
</bindings>
Roman Kiyashev
  • 150
  • 1
  • 11