C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How to use Webservices over SSL


Posted Date: 08 Nov 2004    Resource Type: Articles    Category: .NET Framework
Author: Ramakrishnan.V.SMember Level: Bronze    
Rating: 1 out of 5Points: 3



The problem

When you deploy a webservice in SSL and a reference to it from your project and try to create a instance of that webservice you may face a problem which says :

"Truted connection could not be established".

For exmaple the below code creates a intsnace of your web service

 myweb.MySSL obj=new myweb.MySSL(); /// u r webservice instance 


A simple method for solving this problem in using web service over SSL is to use "ServicePointManager" & "ICertificatePolicy" of Sytem.net namespace.

The solution

The following code snippet can give you an idea to solve the problem
 
using System.net;

private void Button1_Click(object sender, System.EventArgs e)
{

casrv.MySSL obj=new casrv.MySSL(); /// u r webservice instance
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Response.Write(obj.HelloWorld());

}

public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy

{

public TrustAllCertificatePolicy() {}

public bool CheckValidationResult(ServicePoint sp,

X509Certificate cert,

WebRequest req,

int problem)

{

return true;

}

}



Happy R & D.



Responses

Author: N.T.Gopalakrishnan    18 Nov 2004Member Level: Gold   Points : 0
These types of code snippets are really cute and very handy. Thanks for your contribution and continue to do so!!


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: .NET Exception Handling - Part 1
Previous Resource: .NET Exception Handling Part 2 (Creating and Throwing Custom Exceptions)
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use