How to change the http version of my web method method to stop the 505 error?

I need to get some data from a service provider and configure our .net application to point to their hosted web service in order to receive the data. Using the following code when the web method ( ws.DoTransfer ) is 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:

Request failed with HTTP status 505: HTTP version is not supported.

I was told that the HTTP version should be 1.0, but my version 1.1

I read a couple of google posts about this and saw 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, GetWebRequest after base. it is underlined in red and has an error ...

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

Can someone tell me how I change the version of HTTP to 1.0, but still use the same code (rather than building up my own packages with soap) to call my web method?

I can not find any code that I can just enter into my code that looks like the following line ...

  ws.HttpVersion = HttpVersion.Version10; 

thanks

+4
source share
2 answers

Change Expect100Continue to false. You can do this in the configuration file of your application by adding the following:

 <configuration> <system.net> <settings> <servicePointManager expect100Continue="false" /> </settings> </system.net> </configuration> 
+11
source

If you cannot override GetWebRequest , you are using the WCF service, not the Soap web service. WCF does not support HTTP / 1.0

To create a link to a web service that allows you to use the HTTP / 1.0 protocol

  • Right-click the project and select Add Service.
  • Click the "Advanced" button
  • Click the Add Web Link link

If you use the same namespaces as before, no code changes are required.

+4
source

Source: https://habr.com/ru/post/1389722/


All Articles