Search code examples
c#httpsoapwsdlwireshark

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)

postman vs C# client

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


Solution

  • 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;
        }