Call the WebService method deployed under SSL (Microsoft. NET Framework SDK V2.0)
Private void btncall_click (Object sender, eventargs E)
{
// SOAP request information (obtained from the WSDL Analysis)
Stringbuilder sb = new stringbuilder ();
SB. append ("<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> \ R \ n ");
SB. append ("<soap: envelope xmlns: xsi = \" external "xmlns: XSD = \" http://www.w3.org/2001/xmlschema\ "xmlns: Soap = \" external "> \ r \ n ");
SB. append ("<soap: Body> \ r \ n ");
SB. append ("<m: getdata xmlns = \" http: // 127.0.0.1/xfirewebservice/services/helloworld \ "/> \ r \ n ");
// Sb. append ("<getdata xmlns = \" http://tempuri.org/\ "/> \ r \ n ");
SB. append ("</soap: Body> \ r \ n ");
SB. append ("</soap: envelope> \ r \ n ");
Byte [] sendbyte = system. Text. encoding. utf8.getbytes (sb. tostring ());
Try
{
// Load the certificate (this certificate is exported from IE)
String certificatefile = @ "C: \ out. Cer ";
X509certificate certificate = x509certificate. createfromcertfile (certificatefile );
// Verify
Servicepointmanager. servercertificatevalidationcallback = new system. net. Security. remotecertificatevalidationcallback (checkvalidationresult );
// Generate a Web Request
Httpwebrequest request = (httpwebrequest) webrequest. Create ("https: // 192.168.100.153/cupit/messageio ");
// Httpwebrequest request = (httpwebrequest) webrequest. Create ("http: // localhost: 2022/WS/service. asmx ");
// Set Request attributes
Request. clientcertificates. Add (certificate );
Request. method = "Post ";
Request. contenttype = "text/XML; charsets = UTF-8 ";
Request. contentlength = sendbyte. length;
Stream rstream = request. getrequeststream ();
// Send the soap File
Rstream. Write (sendbyte, 0, sendbyte. Length );
// Obtain the Server Response (return value)
Httpwebresponse response = (httpwebresponse) request. getresponse ();
Stream receivestream = response. getresponsestream ();
Streamreader readstream = new streamreader (receivestream, encoding. utf8 );
// Save the reverse return value to the file
String getdatafile = @ "C: \ getdata. xml ";
If (file. exists (getdatafile ))
{
File. Delete (getdatafile );
}
Filestream FS = new filestream (getdatafile, filemode. Create );
Streamwriter Sw = new streamwriter (FS, encoding. utf8 );
Sw. Write (readstream. readtoend ());
Sw. Close ();
FS. Close ();
MessageBox. Show ("OK ");
Request. getresponse ();
Response. Close ();
Readstream. Close ();
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}
Public bool checkvalidationresult (Object sender, x509certificate certificate, x509chain chain, sslpolicyerrors errors)
{
Return true;
}