Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

c# - add web service reference from behind a proxy server

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...