zoukankan
html css js c++ java
调用部署在SSL下的WebService的方法
调用部署在SSL下的WebService的方法
(Microsoft .NET Framework SDK v2.0)
private
void
btnCall_Click(
object
sender, EventArgs e)
{
//
SOAP 请求信息(从WSDL分析得出)
StringBuilder sb
=
new
StringBuilder();
sb.Append(
"
<?xml version=\
"
1.0
\
"
encoding=\
"
utf
-
8
\
"
?>\r\n
"
);
sb.Append(
"
<soap:Envelope xmlns:xsi=\
"
http:
//
www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"
http://www.w3.org/2001/XMLSchema
\" xmlns:soap=\"
http://www.w3.org/2003/05/soap-envelope
\">\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
{
//
加载证书(这个证书从IE中导出来的)
string
certificateFile
=
@"
c:\out.cer
"
;
X509Certificate certificate
=
X509Certificate.CreateFromCertFile(certificateFile);
//
验证
ServicePointManager.ServerCertificateValidationCallback
=
new
System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
//
生成Web请求
HttpWebRequest request
=
(HttpWebRequest)WebRequest.Create(
"
https://192.168.100.153/CUPIT/MessageIO
"
);
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("
http://localhost
:2022/ws/Service.asmx");
//
设置请求属性
request.ClientCertificates.Add(certificate);
request.Method
=
"
POST
"
;
request.ContentType
=
"
text/xml; charset=utf-8
"
;
request.ContentLength
=
sendByte.Length;
Stream rStream
=
request.GetRequestStream();
//
发送SOAP文件
rStream.Write(sendByte,
0
, sendByte.Length);
//
获得服务器相应(返回值)
HttpWebResponse response
=
(HttpWebResponse)request.GetResponse();
Stream receiveStream
=
response.GetResponseStream();
StreamReader readStream
=
new
StreamReader(receiveStream, Encoding.UTF8);
//
把反回值保存到文件里
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
;
}
查看全文
相关阅读:
leetcode8.字符串转换整数(atoi)
leetcode7、整数反转
leetcode6.Z字形变换
leetcode5.最长回文子串
leetcode4.寻找两个正序数组的中位数
leetcode3. 无重复字符的最长子串
leetcode 2.两数相加
leetcode 1. 两数之和
post&get请求总结
oracle知识总结
原文地址:https://www.cnblogs.com/sun_moon_earth/p/751517.html
最新文章
Week6 限时大模拟 掌握魔法の东东 II Gym
Week6 作业 D
Week6 作业 C
Week6 作业 B
Week6 作业 A
Week5 作业 D
Week5 作业 C
Week5 作业 B
Week5 作业 A
Week4 作业 A
热门文章
shell编程实例A01
printf "