5

I need to get some data from a service provider and have configured our .net app to point to their hosted web service to get the data. Using the code below, when the web method is called (ws.DoTransfer) I get the following error...

    private void DoTransferLocal()
    {
            Version version = new Version();
            string error = string.Empty;
            try
            {
                    RemoteService ws = new RemoteService();
                    ServicePoint spm = ServicePointManager.FindServicePoint(new Uri(ws.Url));
                    spm.Expect100Continue = true;
                    version = spm.ProtocolVersion;
                    ws.Credentials = credentials;
                    ws.PreAuthenticate = true;
                    RemoteResult result = ws.DoTransfer();
                    MessageBox.Show("Result = " + result.transferStatus);
            }
            catch (Exception ex)
            {
                    error = ex.Message;
            }
            finally
            {
                    MessageBox.Show(version.ToString() + Environment.NewLine + error);
            }
    }

Error:

The request failed with HTTP status 505: HTTP Version Not Supported.

I've been told that the version of the HTTP needs to be 1.0, but mine is 1.1

I've read a couple of google posts about this and have seen suggestions to override the GetWebRequest method as shown here...

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {   
            System.Net.HttpWebRequest request = base.GetWebRequest(uri) as System.Net.HttpWebRequest;
            request.ProtocolVersion = System.Net.HttpVersion.Version10;
            return request;
    }

...but when I try this, the GetWebRequest after base. is underlined in red and has the error...

'Object' does not contain a definition for 'GetWebRequest'

Can anyone tell me how I change the HTTP version to 1.0, but still use similar code (rather than building up my own soap packets) to call my web method?

I can't seem to find any kind of code that I can simply inject into my code that looks like the following line...

    ws.HttpVersion = HttpVersion.Version10;

Thanks

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
Karl
  • 912
  • 2
  • 16
  • 28

2 Answers2

11

Change the Expect100Continue to false. You can do it in the config file of you app, adding the following:

<configuration>
    <system.net>
        <settings>
            <servicePointManager expect100Continue="false" />
        </settings>
    </system.net>
</configuration>
Catalin S
  • 130
  • 1
  • 4
4

If you are unable to override GetWebRequest, you are using a WCF service and not a Soap web service. WCF does not support HTTP/1.0

To create a Web Service reference that will allow you to use the HTTP/1.0 protocol

  • Right click on project and select Add Service.
  • Click on the Advanced button
  • Click on the Add Web Reference

If you use the same namespace as before, no code changes should be required

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
  • I am having the same exact issue with Cisco AXL webservice. I have used wsdl.exe to compile teh *wsdl and *xsd files. I followed the steps above, but I can't point it to the wsdl file??!! It says access to path is denied, and I tried to run visaul studio as admin still no luck – laitha0 Jul 10 '13 at 20:11