.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Thursday, January 04, 2007

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!

0 comments: