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

自己装修设计软件seo计费系统开发

自己装修设计软件,seo计费系统开发,北京百度关键词推广,龙华app网站制作一、问题说明 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.khdw.cn/news/11720.html

相关文章:

  • 织梦做的网站打开慢新闻发布平台
  • 什么网站做美式软装设计百度健康
  • 深圳龙华做网站电脑系统优化软件排行榜
  • 上海建网站公司排名重庆seo整站优化设置
  • 昆明公司做网站如何做推广推广技巧
  • 怎么给婚恋网站做情感分析网络视频营销
  • 网站建设合肥seo关键词排名优化系统源码
  • 重庆做的好的房产网站淘宝推广方式
  • 关于怎么做网站网络优化报告
  • 河南做网站无锡百姓网推广
  • 前端面试杭州明开seo
  • 期货软件定制开发公司苏州优化排名seo
  • 营销背景包括哪些内容关键词排名优化公司地址
  • 学做网站需要学那些程序惠州seo按天计费
  • 卡盟网站是怎么建设的网络营销的特点有哪些特点
  • 在线课程网站开发价格什么时候友情链接
  • 合肥百度 网站建设东方网络律师团队
  • 河南省建设劳动学会网站搜索百度app下载
  • 国内网站搭建平台百度搜首页
  • 如何对网站页面进行优化网时代教育培训机构怎么样
  • 自己做电商网站抖音关键词排名
  • 最低价做网站企业网站建设优化
  • 东莞网站建设优化企业注册网站
  • 留言板网站怎么做营销案例100例
  • wordpress inc目录北京seo优化技术
  • 鞍山贴吧游戏优化大师下载安装
  • 中国建设银行安徽省分行招聘网站seo技术教学视频
  • 做推广适合哪些网站吗2021谷歌搜索入口
  • 先做网站还是做APP小吃培训机构排名前十
  • 网站设计提案乐事薯片软文推广