It is possible that the wsdl for the web service is "arguing" with the domain name and the SSL certificate. IIS will autogenerate a web service's WSDL using the IIS registered domain name (which by default is the machine name on the local domain, not necessarily your web domain). If the certificate domain doesn't match the domain in the SOAP12 Address you will receive communication errors.
views:
1843answers:
4Read the entity body of the error response. It might have a hit as to what is happening.
the code to do that is as follows:
catch(WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
WebResponse resp = e.Response;
using(StreamReader sr = new StreamReader(resp.GetResponseStream())
{
Response.Write(sr.ReadToEnd());
}
}
}
That should show the full contents of the error response, and it might have a hint.
With the help of this I got a more detailed description of the problem: The proxy was returning the message: "The user agent is not recognized." So I set it manually. Also, I changed the code to use GlobalProxySelection.GetEmptyWebProxy(), as described here. The final working code is included below.
private static string SendRequest(string url, string postdata)
{
if (String.IsNullOrEmpty(postdata))
return null;
HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(url);
// No proxy details are required in the code.
rqst.Proxy = GlobalProxySelection.GetEmptyWebProxy();
rqst.Method = "POST";
rqst.ContentType = "application/x-www-form-urlencoded";
// In order to solve the problem with the proxy not recognising the user
// agent, a default value is provided here.
rqst.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
byte[] byteData = Encoding.UTF8.GetBytes(postdata);
rqst.ContentLength = byteData.Length;
using (Stream postStream = rqst.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
postStream.Close();
}
StreamReader rsps = new StreamReader(rqst.GetResponse().GetResponseStream());
string strRsps = rsps.ReadToEnd();
return strRsps;
}
Может быть из-за того, что обращение идет к локальному ресурсу, тогда, начиная с Framework 2 нужно игнорировать прокси:
IWebProxy myProxy = GlobalProxySelection.GetEmptyWebProxy();
GlobalProxySelection.Select = myProxy;
Perhaps due to the fact that the treatment goes to the local resource, then, starting with the Framework 2, to ignore the proxy:
IWebProxy myProxy = GlobalProxySelection.GetEmptyWebProxy ();
GlobalProxySelection.Select = myProxy;