ASP.Net consuming Java WebService – Some observations


1) If your web service is protected by SSL, you are likely to get this error,The underlying connection was closed: Could not establish trust relationship with remote server.
Possible Solution:Add a class that implements ICertificatePolicypublic 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 errorThe 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s