首页 > 其他 > 详细

SOAP协议的学习

时间:2021-04-30 14:59:43      阅读:17      评论:0      收藏:0      [点我收藏+]

soap协议是基于xml文档的传输协议,程序中生成soap请求报文内容。

(1) 创建xml文档

 XmlDocument doc = new XmlDocument();

(2) 生成soap信封

doc.LoadXml("<soap:Envelope

xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/

soap/envelope/\"></soap:Envelope>");

(3)设置xml文档版本声明

AddDelaration(doc);

也就是下面的函数

private static void AddDelaration(XmlDocument doc)
{
  XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
  doc.InsertBefore(decl, doc.DocumentElement);
}

顺便学习下doc.insertBefore()以及createXmlDeclaration()函数的用法

技术分享图片

 

 技术分享图片

 

 (4) 生成内容body部分

 XmlElement soapBody = doc.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");

微软文档中createElement的用法,Prefix为该节点的命名空间前缀

技术分享图片

 

 

 

 

完整程序:

技术分享图片

 

SOAP协议的学习

原文:https://www.cnblogs.com/MyWPF/p/14721464.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!