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 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:
- Explicitly set the proxy to the request object copying settings from IE (proxy is used there) and it worked.
- Explicitly set the proxy to null and it also worked.
Now, I have several questions:
- Why under IIS 7.5 the initial code is not working, however in console app everything works as expected?
- 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.
- 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.
精彩评论