Raise the time-out for a single webservice - c#

My web configuration looks as follows:
<system.web>
<compilation debug="false"/>
<httpRuntime executionTimeout="90"/>
</system.web>
This is fine for most webservice functions but one function has a query that is running a very long (5 minutes) time and will be stopped before it has finished. Is it possible to set the runtime to 5 minutes for this webservice alone?
E.g.:
MyWebServices.asmx?op=WS_LongMethod --> Timeout of 5 minutes
I've thought about running the database query async (fire and forget) but it doesn't seem possible with sybase/oracle through ODBC.

Yes, you can do that. In the web.config, you'll need to add a <location/> element:
<location path="Path_To_Your_Service.asmx">
<system.web>
<httpRuntime executionTimeout="90"/>
</system.web>
</location>
The <location/> element gives you a mechanism whereby you can apply web.config attributes to specific paths within your site.

You can use a delegate within your webservice to call another method asynchronously. Within this method you can do your database IO. This means you will return to the caller before the operation is complete, however if you generate a unique ID and store any info related to that ID, then you can retrieve it at a later date.

Did you check the .Timeout property of web service?
Indicates the time an XML Web service client waits for a synchronous XML Web service request to complete (in milliseconds).

Related

ASP.NET Web API request does not reach controller action

I have trouble posting 'large' objects to my web api using the HttpClient's PostAsJsonAsync method. The objects contain a base64 encoded image file.
After a period which seems like the client's timeout setting, the exception
'A task was canceled.'
is thrown by the HttpClient. The timeout is already set very high (10 minutes). This only happens with files larger than ~2 MB. Anything smaller works fine. I know that the request does not even hit the first line of code in the controller method because the first line is a logging line and the log is empty. There are no exceptions in the server event viewer.
It is hard to pin down the issue because the controller works fine when I deploy the web api on my local IIS. But when I deploy it on my Azure VM, it only work for small files. The web.config files are identical.
maxRequestLength is already set high enough.
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />
Instead of IIS hosting in an Azure VM, i've just tried to deploy the API as an app service. The exact same thing happens there.
You can also try setting this limit:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Note that contrary to the maxRequestLength parameter, this value is in bytes.

How to return 504 (gatewayTimeout) in WebApi

In my company API (we use WebAPI 2) we want to return 504 (gateway timeout) when controller action takes to much time. Sometimes inside our WebAPI actions we cooperate with external company APIs, which not always work correctly, so it could be convinient for user.
I added entry in web.config, but it doesn't work.
<system.transactions>
<defaultSettings timeout="00:00:10" />
</system.transactions>
How can I resolve this problem?
timeout is set in number of seconds, and I Think you should use httpruntime executiontimeout instead of transaction timeout wich only affects the transactions within the request
<system.web>
<httpRuntime executionTimeout="10" />
</system.web>

ASP.NET - when button click operation takes more than 1 hour gets internet explorer cannot display webpage errror

I am developing asp.net web application which extracts records from database and rest api.
When click extract button on page, it extracts records and redirects to other page which shows the extracted records.
While redirecting other page, I stored extracted records in session.
Up to 20k records, I haven't face with any issue which takes less than 1 hour. But when I try to extract more than 20k records, I am getting "Internet explorer cannot display webpage" error in middle of extraction without any exception.
I hosted application on server and also tried from my local, result is always same.
I don't make any ajax call.
Can you guys please give me any suggestion?
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"/>
<customErrors mode="Off" defaultRedirect="Error.aspx" />
<sessionState timeout="2880" mode="InProc"></sessionState>
<httpRuntime maxRequestLength="360000000" executionTimeout="360000000"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Thanks
I think that letting browser wait for an hour is far from optimal in any case. A far better solution would be to trigger an asynchronous operation and then use AJAX pooling to check if the extraction is complete and after it gets done, redirect.

MVC 'Find' method taking a long time (even in release)? (Using miniprofile)

I'm using MiniProfile to try and figure out why my MVC site is taking a long time. It looks like the 'Find' method is where the time is being spent. I have read a couple things on this and most people seemed to suggest that it was due to having <compilation debug="true" .. > set in the web.conf. I can confirm that in the following example the debug is not set (my compilation looks like the following):
<compilation targetFramework="4.0">
...
</compilation>
No where is debug mentioned. But yet, my find calls are taking upwards of three seconds :S
Any suggestions on how I can figure this out? (Note: I am running on an Azure production server. I have RDC'd into the system to confirm that the pushed web.config does not contain the debug="true").
If this is the first request coming to your website after publishing or after the AppDomain has been brought down by IIS it is normal that the Find method takes a long time. It will then cache the location for this view and on subsequent requests it should be much faster. Try Ctrl+F5ing in your browser on the same url.
Also try explicitly setting debug="false" in your web.config.

How to increase the POST size for an ASMX web service?

Background
I am developing an ASP.Net server side control that needs to talk to an ASMX web service. The server side control uses a WebClient object to talk to the web service, since it needs to be reused often in various application, and to make it easier on the developers, they are not required to create a service reference to the web service.
Implementation
During the use of the control, it is requires the sending of a serialised object to the web service. The object is serialised using the XmlSerializer and the resulting XML string is then compressed using the chilkat compression library. The web service call for the control looks as follows:
webClient.UploadStringAsync(new Uri(serviceHost + serviceMethod), "POST", sendData)
The content of sendData (string) is compressedResponse={CompressedData}.
The web service has a method defined as follows to receive the data and then decompress the string value using the chilkat library before de-serialising the object using the XmlSerializer.
public void SaveResponse(string compressedResponse)
The communication between the control and the service is working. Initially there were no settings or binding defined in the web.config for any of the above. After initial searching I did add
<httpRuntime maxRequestLength="20480"/>
to both the client and server web.config files. This has made no difference.
Problem
Compressed or uncompressed the data being posted to the web service in the sendData variable is to big for a normal POST request, and is corrupted. This is confirmed when checking the last few characters of the string before and after it being posted to the server in compressed format, and uncompressed, the Xml document is missing the last root tag when checking in the debugger. The string can't be decompressed and therefore the service call fails every time.
How do I increase the POST size for the WebClient request to ensure that the full string is received by the server?
I have looked at the various option on Google, but none are giving me a good enough sample of where to make the changes, or samples of what the changes need to look like. I am completely lost as to whether the change needs to be made on the server or the consuming website, and since there are no binding defined for this, how to create a binding in the web.config for an ASMX HTTP service call.
I believe you must be hitting ASP.NET max request length limit. That you can modify via config file such as:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
maxRequestLength value is in KB, so above setting would allow 20 MB. You can also apply the setting only to selected URLs using location tag e.g.
<location path="yourservice.asmx">
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
</location>
There seems to be no way to change the POST size for a ASMX Web Service when only HttpPost is enabled.
The solution in the end was to switch the service to running HttpSoap and create a service reference to the assembly containing the control. Once done the binding is created using code in the control once the endpoint is set via a property.

Categories

Resources