当前位置: 首页 > news >正文

网站做推广 建设哪种类型合适石家庄做网站费用

网站做推广 建设哪种类型合适,石家庄做网站费用,wordpress 分类标签云,沈阳有多少网站一、问题说明 1.1 问题描述 使用C# 搭建WebService接口,并按照ESB平台人员的要求,将命名空间改为"http://esb.webservice",使用PostmanESB平台人员提供的入参示例进行测试时,callBussiness接口参数message始终为null。 以下是ES…

一、问题说明

1.1 问题描述

使用C# 搭建WebService接口,并按照ESB平台人员的要求,将命名空间改为"http://esb.webservice",使用Postman+ESB平台人员提供的入参示例进行测试时,callBussiness接口参数message始终为null

以下是ESB平台提供的模版

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esb="http://esb.webservice"><soapenv:Header/><soapenv:Body><esb:callBussiness><!--Optional:--><message><![CDATA[...]]></message></esb:callBussiness></soapenv:Body>
</soapenv:Envelope>

1.2 C# WebService代码

using System;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Xml;
using System.Xml.Serialization;
using Rss_WebServer.code;namespace ESB
{/// <summary>/// WebService 的摘要说明/// </summary>[WebService(Namespace = "http://esb.webservice")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService]public class WebService : System.Web.Services.WebService{[WebMethod(Description = "调用业务")]public string callBussiness(string message){return message; }}
}

1.3 Postman 测试参数

  • POST http://localhost:55305/WebService.asmx?op=callBussiness
  • Headers
KEYVALUEDESCRIPTION
Content-Typetext/xml; charset=utf-8
SOAPAction“http://esb.webservice/callBussiness”
  • Body
    • raw XML(text/xml)
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esb="http://esb.webservice"><soapenv:Header/><soapenv:Body><esb:callBussiness><!--Optional:--><message><![CDATA[<root><author>少莫千华</author><email>370763160@qq.com</email></root>]]></message></esb:callBussiness></soapenv:Body>
</soapenv:Envelope>

在这里插入图片描述

在这里插入图片描述

二、问题分析

根本问题是ESB平台提供的参数模版并没有完全按照标准的WebService协议进行编写,导致使用官方搭建的WebService接口无法正常的解析参数,所以要想解决此问题,有两个途径:

  • 与ESB平台人员沟通,要求其标准化参数模版
  • 自己重新解构WebService参数

三、解决方案

3.1 与ESB平台人员沟通,要求其标准化参数模版

3.1.1 标准模版 - 使用命名空间缩写

callBussiness接口的message参数添加命名空间缩写esb

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esb="http://esb.webservice"><soapenv:Header/><soapenv:Body><esb:callBussiness><!--Optional:--><esb:message><![CDATA[...]]></esb:message></esb:callBussiness></soapenv:Body>
</soapenv:Envelope>

3.1.1 标准模版 - 使用完整的命名空间

callBussiness接口的使用完整的命名空间<callBussiness xmlns="http://esb.webservice">

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><callBussiness xmlns="http://esb.webservice"><!--Optional:--><message><![CDATA[...]]></message></callBussiness></soapenv:Body>
</soapenv:Envelope>

3.2 自己重新解构WebService参数

从请求对象base.Context.Request中重新获取所有Body内容(InputStream),然后再进行自定义解析。
:因为是搭建的标准的WebService接口Body内容(InputStream)在进去函数内部前已经被SOAP协议解析过一次,所以InputStream起始内容位置Position 指向数据流的结尾,所以在读取之前,先要将InputStream起始内容位置Position设置为0,否则读取的内容为空('')

using System;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Xml;
using System.Xml.Serialization;
using Rss_WebServer.code;
namespace ESB
{/// <summary>/// WebService 的摘要说明/// </summary>[WebService(Namespace = "http://esb.webservice")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService]public class WebService : System.Web.Services.WebService{[WebMethod(Description = "调用业务")]public string callBussiness(string message){try{if (string.IsNullOrEmpty(message)){message = WebServiceAnalysis(base.Context.Request, nameof(message));}return message;}catch(Exception exp){return exp.Message;}}/// <summary>/// 重新解析 WebService/// </summary>/// <param name="request"></param>/// <param name="name"></param>/// <returns></returns>private string WebServiceAnalysis(System.Web.HttpRequest request,string name){try{if(request.ContentLength == 0){throw new Exception($"Body(xml数据) 无数据");}// 获取请求内容Stream inputStream = request.InputStream;// 重新获取内容inputStream.Position = 0;// 读取请求主体内容using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8)){string requestBody = reader.ReadToEnd();XmlDocument xmlDoc = new XmlDocument();xmlDoc.LoadXml(requestBody);XmlNode strNode = xmlDoc.SelectSingleNode($"//{name}");if (strNode != null){return strNode.InnerText;}else{throw new Exception($"未在Body(xml数据)找到{name}节点");}}}catch(Exception exp){throw exp;}}}
}
http://www.yayakq.cn/news/418515/

相关文章:

  • 平邑县住房和城乡建设局网站很多年前的51网站
  • 松滋做网站手机编程免费软件app
  • ip怎么做网站微信贷款怎么申请开通
  • 专门做分析图的网站南昌做网站开发的公司有哪些
  • 外贸网站制作需求代推广平台
  • 经营网站的备案网站seo优化怎么做
  • 网站怎么做图片链接网站建设灬金手指下拉十五
  • 企业网站有哪些内容免费的网页制作
  • 建设部网站查资质6山东大源建设集团网站
  • 免费十八种禁用网站游戏最新新闻热点事件2022年
  • 网站做微信支付宝支付接口企业微信商城
  • asp.net网站建设论文oa系统品牌
  • 百度搜索显示网站logowordpress文章详细页
  • 十大设计网站php和ASP网站那个好
  • 怎么修改自己网站内容公司品牌推广方案范文
  • 石家庄网站建设公司世界工厂网怎么拿货
  • 网站采用什么方法建设吉林省建设安全信息网官网
  • 网站建设策划方怎么建设英文网站
  • 门户网站的含义资海网站建设
  • 网站的内容更新怎么开发wordpress子主题
  • 网站开发需要哪些工程师长沙网站制作方法
  • 手机访问pc网站自动跳转手机端网站代码速效成交型网站
  • 自己做的网站上出现乱码怎么修改wordpress mysqlli
  • 公司网站制作设计联系方式免费空间网站怎么做的
  • `北京网站建设中国字体设计网
  • 深夜小网站公司网站开发视频
  • 网站怎么做seo收录12380网站建设情况汇报
  • 建最便宜的网站要多少钱邢台网站建设要多少钱
  • 北京服饰电商网站建设稿定设计官方免费下载
  • 建设网站哪家专业网站建设项目实践