WCF web service call time out - c#

I am consuming a web service from a url. When I test using SoapUI, I get the response immediately (See image below) and that the request data I sent out made it through to the other end.
So in my C# application I did the same thing, I consumed the web service wsdl and auto generated the proxy class. I create a request based on that proxy class with the exact same request data I used in SoapUI and sent out. I confirmed that at the other end they received my data successfully and no error is shown.
However, I never receive any ID back and after a while I would get this exception:
Error The HTTP request to 'http://someURLWebservice.com/WSoperation' has exceeded the allotted timeout of 00:00:59.9470000. The time allotted to this operation may have been a portion of a longer timeout.
Am I missing something here? I downloaded the WSDL and generated the mock service with SoapUI and if I make a call to that mock web service locally, I would get it right away.the ID back right away.
Here is my code:
string serverURL = Settings.Default.ExtensionServiceURL;
//Get Proxy class client
ext.ExtWSPortTypeClient client = new ext.ExtWSPortTypeClient();
EndpointAddress addr = new EndpointAddress(serverURL);
try
{
client.Endpoint.Address = addr;
Uri site = new Uri(serverURL);
client.Endpoint.ListenUri = site;
ExtensionData eData = new ExtensionData();
client.ChannelFactory.CreateChannel();
Console.WriteLine("Sending Locator Event Request to Web Service");
ext.locatorEventResponse1 resp = await client.locatorEventAsync(eData.GenerateLocatorEventRequest(ev));
}
catch (Exception ex)
{
Console.WriteLine("Error " + ex.Message);
}
finally
{
if (client != null)
{
((ICommunicationObject)client).Close();
}
}

In a similar situation, I would start with the following:
Test with the WCF Client and capture the trace file:
Configure WCF Tracing for the client
(http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx)
Send the message via your WCF Client Application
Let the call timeout and save the trace log data
Test with the soapUI client and capture the Http Log
Clear the soapUI http log (one of the tabs along the bottom)
Send the message via the soapUI test request
Save the Http Log
Once you have the trace information for both clients, you should be able to compare the transactions and hopefully determine the source of the issue. In particular, I would suggest confirming the service addresses on both sides and then comparing the SOAP envelope to make sure the WCF bindings are set consistently with the soapUI settings.
In addition, you could also use Fiddler to view the web service communications. The following SO post provides good reference links. Fiddler and Monitoring Web Service Traffic
Hope this helps.
Regards,

So I ended up configure Fiddler2 to sniff my SoapUI request and compare it against my application request. In the the Application request header I saw the following:
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Host: engage.ext-inc.com
Content-Length: 1036
**Expect: 100-continue**
That Expect:100-continue is not in the SoapUI request which successfully sent out and got the response. With this in mind I took the SoapUI request in Fiddler and compose a new one base on it...except I put in Expect:100-continue and guess what, I received no response.
Upon reading about it I came across this link
And voila, upon putting ServicePointManager.Expect100Continue = false; into my code prior making the web service call I get the response back right away.

Check the message quota settings, it might be that your service is sending more than what is configured

Related

IIS program can receive HTTP Requests and Respond, but when it sends a HTTP Request, it cannot read the Response

I'm using IIS 7.5 with the 4.0 .NET Framework.
Here is the situation.
The IIS program can receive HTTP requests and respond to them. This is confirmed through debugging. However, when a HTTP request is sent from the IIS program, it throws an exception while trying to read the response. Below is the code I'm using ( it is quite standard ).
public static string func( string urlStr )
{
WebClient client = new WebClient();
string content;
try
{
content = client.DownloadString( urlStr );
}
catch( WebException ex )
{
/* Handle the exception */
}
return content;
}
Now, interestingly, I wrote a small c# program to test out this snippet of code. The small standalone c# program works fine. It can send out HTTP requests and receive the responses. The URL's in both cases were identical.
Additionally, using any browser, a browser can get the response using the same URL.
The endpoint of the URL is another program that will respond with a JSON string.
And in the cases of the small c# program and browsers, it does just that.
Only the IIS program throws exceptions while trying to download the string.
Using wireshark, I was able to determine that the URL endpoint is getting the HTTP request and sending the response. However, the response does not make it back to the IIS program.
In all cases, the endpoint was on a different computer.
Below is some information about the exception being thrown.
WebException
WebException.Message: Unable to connect to the remote server
WebException.Status: ConnectFailure
WebException.Response: ( empty )
My question becomes, what could cause this type of behavior?
Are there any configuration properties in IIS that would cause this?
Thank you in advance for your time!
Edit 1
Exception Callstack:
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)

How can I setup fiddlercore catch http request/response that without AfterSessionComplete?

I want to catch a third-party made application's http/https messages with fiddlercore in C#.
I'm not sure what kind of the connection type is but what I did is
FiddlerApplication.OnReadRequestBuffer += FiddlerApplication_OnReadRequestBuffer;
FiddlerApplication.OnReadResponseBuffer += FiddlerApplication_OnReadResponseBuffer;
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
FiddlerApplication.Startup(8888, false, true);
Then I start the application and setup proxy to fiddler's.
The AfterSessionComplete is called only once. The response code is 200 but responseBody is empty.
However, after that I keep receiving OnReadRequestBuffer and OnReadResponseBuffer. The application does keep connecting with the internet(through fiddler proxy)
In my other project I found any messages goes in and out through fiddler should contain one BeforeRequest, then some OnReadRequestBuffer, then following some OnReadResponseBuffer and finally one AfterSessionComplete.
In my mind this is the model of any single post/get process.
But here what I encountered here is that the session won't complete and request -> response -> another requests -> another response...
So how can I catch every full request and the full response to it?
Is there any callback that gives the sign of a full request or a full response is done?
How can I decrypt https base on the partial buffers that runs in and out that caught by OnReadRequestBuffer/OnReadResponseBuffer?
Edit: OnWebSocketMessage is never triggered. Someone says that this kind of protocol could be COMET. But I find nothing about how to catch COMET messages with fiddler. (And I know nothing about COMET)

C# WSDL Client Request Packages

I am currently adding a SOAP-WSDL Service to my project using "Add Service Reference". it creates all necessary classes and functions for me to call. Some of these functions dont give me a response. After 1 minute delay i get a timeout exception. However when i forge the request using Postman (a chrome extension for making network requests) it gets full response. i got suspicious and started to inspect network using Wireshark. after inspection i saw that problem was at the service. but i can't make them fix that. so i need to imitate Postman request using C#.
Main difference between mine and postman is, Postman posts all necessary data in single request for a response, but my client posts just http headers waits for a Http Continue and continues sending necessary data. i guess this breaks the service.
Here are wireshark screenshots for Postman and my client
(Postman is on the left of image and right one is my .net client - sorry for my perfect paint skills)
Is there any configuration on .net wsdl client with basicHttpBinding i can configure to make single request for a call?
edit: when i further investigated my C# client i saw that .net http layer send an initial POST with saying (Expect: 100 Continue), after it receives continue it continues to send SOAP Envelope
edit2: i changed my code to issue request using HttpWebRequest, but .net still sends header and post body with seperate requests (even when i disabled Expect: 100 Continue) and in my theory this breaks service.
question2: is there anyway to say HttpWebRequest, don't split header and body? send all of them in single request?
edit3: i solved the problem. but it wasn't about 100 Continue. service was being broken because of missing User-Agent Header
For HttpWebRequest you can add the following to your .config file - we use this on our service. I'm not, however, sure how it impacts WCF channels.
<configuration>
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
</configuration>
i finally solved the problem. after long inspections and tries i saw that remote service stops responding in the middle of the data communication if i dont add User-Agent HTTP Header. so i added http header using IClientMessageInspector before every request
here is wcf code if anybody needs it
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
HttpRequestMessageProperty realProp;
object property;
//check if this property already exists
if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out property))
{
realProp = (HttpRequestMessageProperty) property;
if (string.IsNullOrEmpty(realProp.Headers["User-Agent"])) //don't modify if it is already set
{
realProp.Headers["User-Agent"] = "doktorinSM/2.1";
}
return null;
}
realProp = new HttpRequestMessageProperty();
realProp.Headers["User-Agent"] = "doktorinSM/2.1";
request.Properties.Add(HttpRequestMessageProperty.Name, realProp);
return null;
}

.Net 4. View consumed web service headers and body from request and response

We're consuming a web service (web reference, not service reference), and I need a way to output the entire message being sent (including headers) and the message that gets received.
When I add the web reference, the generated base type of the client object to send the messages is System.Web.Services.Protocols.SoapHttpClientProtocol
I send the messages like so:
ApiService api = new ApiService();
// set the certificate and basic http network credentials
var response = api.SendRequest(messageObject);
I'm able to get the body of the request by serializing messageObject, but can't figure out how to get the full message with the headers.
Since I'm using a certificate and basic authentication, tools like Fiddler, etc. aren't getting me what I need, so I believe I have do something programmatically to pull whats sent and whats received prior to being encrypted with ssl.
EDIT
What I want to see if the data being sent and received to another service from within my WCF service.... e.g.:
// this function is within my WCF service
public ResponseModel Auth()
{
// call to another service here... need to trace this
}
If this is for tracing purposes I have had some success using the tracing capabilities of the System.Net libraries, you should be able to enable the tracing through configuration only.
It's described here: How to: Configure Network Tracing
The resulting log file isn't the easiest to follow, but is described here: Interpreting Network Tracing

Get SOAP request body in proxy client

I have application which calls a WCF service. For monitoring and tracking purposes I would like to have log all request messages for which application failed to call a service. Loke I need to call operation called RemoveSubscription and once failed(may be network problem or WCF service was down) I would like to log the SOAP message into xml or txt file.
Generaly is it possible to get the request SOAP contact in proxy class.
I found some info that it can be done by extending SoapExtension class. If this is the right way how to register/inject the new class which extends SoapExtension to channel stack.
EDIT : Service is not hosted in IIS it is in Windows service... so I am i right that in this case SoapExtension is not the right solution.
With a WCF based client, you can create an endpoint behavior to intercept the request & response messages. This TechNet article shows how to access the message being sent and the response message. Your WCF client can be generated by either adding a Service Reference in Visual Studio, using SvcUtil to manually generate your client code or rolling your own proxy directly in code using the ChannelFactory class.
Your logging code would always write out the request message with a status of requested and a timestamp to some data store (file, database, etc.) When the response message is received, it would match request message somehow from the response message contents and update the data store to change the status to responded. Selecting all the messages from the data store with the status of requested older that some time period would list all the failed messages.

Categories