The underlying connection was closed: Could not establish trust relationship with remote server.
Possible Solution:Add a class that implements ICertificatePolicy
public class PolicySubClass : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint , X509Certificate certificate , WebRequest request , int certificateProblem) {
//Return True to force the certificate to be accepted. return true;
} }
Then in your class code, addSystem.Net.ServicePointManager.CertificatePolicy = new PolicySubClass();2) If you are accessing your web service via a proxy, you might get this error
The underlying connection was closed: The server committed an HTTP protocol violation.
If you google this issue, you will find suggestions to fix this in couple of different ways.First approach is to modify web.config to add section like this:
In my case, this did not help, I had to do this in my code,
WebProxy proxyObject = new WebProxy("http : // myproxy:10001", true); wsproxy.Proxy = proxyObject;
here, wsproxy is the your web service proxy variable.
3) For many of the connection based errors/issues, many suggest to subclasss your web serviceproxy class to set the HTTP Keep Alive to false
public class ProxySubClass : MyWebServiceProxy { public ProxySubClass(){}
protected override System.Net.WebRequest GetWebRequest(Uri uri) { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest) base.GetWebRequest(uri); webRequest.KeepAlive = false; return webRequest;
} }
4) As a rule of thumb, when ever there is a connection issue to a web service, start by pasting the web service URL to your web browser address window and try to access the wsdl.If this works, then start trying the above said tweaks!
Cheers!
0 comments:
Post a Comment