简体   繁体   中英

Executing HttpWebRequest from WCF hosted by IIS 7.5

I have the following weird situation.

I am trying to execute the following sequence of code within a WCF service, hosted in IIS 7.5 Express:

 var request = WebRequest.Create(some_uri) as HttpWebRequest;

 request.Method = "GET";
 request.Credentials = CredentialCache.DefaultNetworkCredentials;

 request.GetResponse();

When executed from a WCF service, I get the following exception:

[WebException: Unable to connect to the remote server]

and its inner exception:

[SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:400]

The same sequence of code from the console application is executed successfully.

I tried the following things for the code running under IIS 7.5 Express:

  1. Explicitly set the proxy to the request object copying settings from IE (proxy is used there) and it worked.
  2. Explicitly set the proxy to null and it also worked.

Now, I have several questions:

  1. Why under IIS 7.5 the initial code is not working, however in console app everything works as expected?
  2. What is the difference between the original code and the first solution? As I understand, if I do not specify the proxy, by default, the IE proxy settings will be applied. However, it turns out that the solutions are not equivalent.
  3. Is there any other solution to make the call originated from WCF successfully?

IIS代码在IIS用户帐户下运行,该帐户可能未配置您的代理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM