开发者

Executing HttpWebRequest from WCF hosted by IIS 7.5

开发者 https://www.devze.com 2023-04-12 05:25 出处:网络
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:

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 in开发者_JAVA技巧ner 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?


The IIS code is running under an IIS user account, which probably doesn't have your proxy configured.

0

精彩评论

暂无评论...
验证码 换一张
取 消