Pregunta

I'm using vs2010. In a simple console app I try to add a service reference to http://***/service1.asmx , old asmx service. My computer is behind a proxy server, so i get an error :

"The remote server returned an unexpected response: (407) Proxy Authentication Required."

When im using wsdl tool i can not define proxy server port number and i get message that server, for examle 10.0.0.3:80, did not respond, but i need to specify 8080 port and don't know how. How could i create a reference?

¿Fue útil?

Solución

Take a look at the links below for specifying the proxy address and server port when adding a web reference.

http://msdn.microsoft.com/en-us/library/bb628649.aspx

http://msdn.microsoft.com/en-us/library/03seed2h.aspx

To add a reference to an asmx

  1. Right click on the console app and select add service reference.

  2. Click on the advanced button and enter the asmx address in the address bar. Click on the green button next to it to discover the asmx.

  3. Give it a name and click on add ref.

Update: try updating web config/ app config and add;

<system.net>

<defaultProxy>
<proxy usesystemdefault="True" proxyaddress="http://[your proxy address and port number]"  bypassonlocal="True"/>

</defaultProxy>

</system.net>

Otros consejos

I spent almost 50 hours finding the problem, could not find anywhere on the web this simple solution.

Under "configuration" section in Web.config add this:

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>

Then works like a charm!

You can also do it from the code behind:

serviceConnection = new WebService1();
serviceConnection.Proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
serviceConnection.Proxy.Credentials = CredentialCache.DefaultCredentials; 

Works beautiful!!.

If you need to consume from HTTPS location add this configuration:

<message clientCredentialType="Certificate" algorithmSuite="Default" />

Adding the Reference:

Make sure that you are adding the Reference like this. You need to click on "Add Service Reference", go to "Advanced" and finally click on "Add Web Reference".

Then add the following:

http://***/service1.asmx

For port 8080 you use:

http://***:8080/service1.asmx

Setup the Proxy for your Web Service:

To make sure that the Web Service is using your Internet Explorer proxy you can add the following to your Web Serviceobject on your client application.

webService1.Proxy = WebRequest.GetSystemWebProxy();

You can also set up the Proxy manually:

webService1.Proxy = new WebProxy("hxxp://my-proxy-settings:8080/");

NTLM

If you use NTLM you will probably need to make sure that you use the Default Credentials on your client project as well. You can easily do this by passing it in when creating the Web Serivce using UseDefaultCredentials set to true.

public webService _webService = new webService() { UseDefaultCredentials = true };

You can also disable NTLM Authentication for your Web Service project. You can do this under Project Properties -> Web. If you uncheck this option you should be able to add the Web Service without having to authenticate.

http://msdn.microsoft.com/en-us/library/aa378749.aspx

I cannot automatically create web service reference using vs2010. I decide to use wsdl.exe tool, and in parameter named /parameters pass xml file with proxy server credentials

wsdl.exe http://service uri/service1.asmx /parameters:c:\temp\wsdlparameters.xml

WSDL.exe generate a file Service1.cs (default). I add this file to my project and use it like this :

WebProxy wp = new WebProxy(@"YourProxyServer",ProxyPort);
wp.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
Service1 service1 = new Service1();
service1.Proxy = wp;
service1."YourServiceMethod"();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top