wcf第3步之报文分析及原生调用
最简单的调用当然是服务引用,但是我更想原生调用,所以希望能通过报文有如下研究
1.报文分析
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="DemoService" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo"/>
<xsd:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/DataTypes"/>
<xsd:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd4" namespace="http://schemas.datacontract.org/2004/07/System"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IDemoService_DoSomething_InputMessage">
<wsdl:part name="parameters" element="tns:DoSomething"/>
</wsdl:message>
<wsdl:message name="IDemoService_DoSomething_OutputMessage">
<wsdl:part name="parameters" element="tns:DoSomethingResponse"/>
</wsdl:message>
<wsdl:portType name="IDemoService">
<wsdl:operation name="DoSomething">
<wsdl:input wsaw:Action="http://tempuri.org/IDemoService/DoSomething" message="tns:IDemoService_DoSomething_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IDemoService/DoSomethingResponse" message="tns:IDemoService_DoSomething_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IDemoService" type="tns:IDemoService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="DoSomething">
<soap:operation soapAction="http://tempuri.org/IDemoService/DoSomething" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DemoService">
<wsdl:port name="BasicHttpBinding_IDemoService" binding="tns:BasicHttpBinding_IDemoService">
<soap:address location="http://dev.xxx.io/Demo/DemoService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
可以看到
1.wcf服务地址
http://dev.xxx.io/Demo/DemoService.svc 2.引用了4个命名空间
Serialization
Contracts.Models.Demo
DataTypes
System 3.Service的名称及接口 DemoService,
IDemoService 4.服务接口的方法
DoSomething 再访问
来读取类型的具体字段
http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/DataTypes" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DataTypes">
<xs:complexType name="Request">
<xs:sequence>
<xs:element minOccurs="" name="UserId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Request" nillable="true" type="tns:Request"/>
<xs:complexType name="Response">
<xs:sequence>
<xs:element minOccurs="" name="ErrorCode" type="xs:int"/>
<xs:element minOccurs="" name="Message" nillable="true" type="xs:string"/>
<xs:element minOccurs="" name="Success" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Response" nillable="true" type="tns:Response"/>
</xs:schema>
http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd0
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo"/>
<xs:element name="DoSomething">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo" minOccurs="" name="request" nillable="true" type="q1:SomeReq"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DoSomethingResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo" minOccurs="" name="DoSomethingResult" nillable="true" type="q2:SomeResp"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd2
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Contracts.Models.Demo">
<xs:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd4" namespace="http://schemas.datacontract.org/2004/07/System"/>
<xs:import schemaLocation="http://dev.xxx.io/Demo/DemoService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/DataTypes"/>
<xs:complexType name="SomeReq">
<xs:complexContent mixed="false">
<xs:extension xmlns:q1="http://schemas.datacontract.org/2004/07/DataTypes" base="q1:Request">
<xs:sequence>
<xs:element minOccurs="" name="Date" type="xs:dateTime"/>
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/System" minOccurs="" name="DateUTC" type="q2:DateTimeOffset"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="SomeReq" nillable="true" type="tns:SomeReq"/>
<xs:complexType name="SomeResp">
<xs:complexContent mixed="false">
<xs:extension xmlns:q3="http://schemas.datacontract.org/2004/07/WHTR.DataTypes" base="q3:Response">
<xs:sequence>
<xs:element minOccurs="" name="Date" type="xs:dateTime"/>
<xs:element minOccurs="" name="DateStr" nillable="true" type="xs:string"/>
<xs:element minOccurs="" name="ResultDate" nillable="true" type="xs:string"/>
<xs:element minOccurs="" name="ResultDateUTC" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="SomeResp" nillable="true" type="tns:SomeResp"/>
</xs:schema>
根据以上信息,可以生成的最简单的 Contract代码如下:
[Serializable]
[DataContract(Name = "Response", Namespace = "http://schemas.datacontract.org/2004/07/DataType")] public class Response
{
[DataMember]
public int ErrorCode { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public bool Success { get; set; }
} /// <summary>
/// SomeResponse
/// </summary>
[DataContract(Name = "SomeResp", Namespace = "http://schemas.datacontract.org/2004/07/DataType")] [Serializable]
public sealed class SomeResp : Response
{
/// <summary>
/// 时间格式的Date
/// </summary>
[DataMember]
public DateTime Date { get; set; } /// <summary>
/// 格式成字符串的时间
/// </summary>
[DataMember]
public string DateStr { get; set; } /// <summary>
/// 返回传入的Date
/// </summary>
[DataMember]
public string ResultDate { get; set; } /// <summary>
/// 返回传入的Date
/// </summary>
[DataMember]
public string ResultDateUTC { get; set; }
} [Serializable] [DataContract(Name = "Request", Namespace = "http://schemas.datacontract.org/2004/07/Contracts.Models.Demo")]
public class Request
{
[DataMember]
public string UserId { get; set; }
} /// <summary>
/// SomeRequest
/// </summary>
[DataContract(Name = "SomeReq", Namespace = "http://schemas.datacontract.org/2004/07/Contracts.Models.Demo")]
[Serializable] public sealed class SomeReq : Request
{
/// <summary>
/// 时间
/// </summary>
[DataMember]
public DateTime Date { get; set; } /// <summary>
/// Data
/// </summary>
[DataMember]
public DateTimeOffset DateUTC { get; set; } } /// <summary>
/// IDemoService
/// </summary>
[ServiceContract ] public interface IDemoService
{
/// <summary>
/// Does something.
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
[OperationContract ]
SomeResp DoSomething(SomeReq request);
}
具体调用代码如下:
using System.Runtime.Serialization;
using System.ServiceModel;
EndpointAddress address = new EndpointAddress("http://dev.xxx.io/Demo/DemoService.svc?wsdl");
BasicHttpBinding binding = new BasicHttpBinding();
ChannelFactory<IDemoService> factory = new ChannelFactory<IDemoService>(binding, address);
IDemoService channel = factory.CreateChannel();
var result = channel.DoSomething(new SomeReq()
{
Date = DateTime.Now
});
wcf第3步之报文分析及原生调用的更多相关文章
- 一次http完整的请求tcp报文分析
一次http请求的报文分析 数据包如下: 第一个包113.31的主机(下边称之为客户端)给114.80的主机(下边称之为服务器)发送一个syn包请求建立连接 第二个包服务器回复客户端syn+ack表示 ...
- Wireshark安装使用及报文分析(图文详解)
Wireshark是世界上最流行的网络分析工具.这个强大的工具可以捕捉网络中的数据,并为用户提供关于网络和上层协议的各种信息.与很多其他网络工具一样,Wireshark也使用pcapnetwork l ...
- HTTP 请求报文和响应报文分析和解刨!!
http请求和响应报文分析 一>http请求报文主要包括三个部分:1.请求行:2.请求头:3;请求体: 1,请求行一般包括三个部分:请求方式:请求url : http协议版本. 请求方法:大部分 ...
- http协议请求报文与响应报文分析
什么是HTTP协议: HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到 不断地完善和扩展.目前在WWW中使用 ...
- Wireshark安装使用及报文分析
先看链接!!! Wireshark使用教程:https://jingyan.baidu.com/article/93f9803fe902f7e0e56f5553.html Wireshark过滤规则筛 ...
- Spring源码分析之`BeanFactoryPostProcessor`调用过程
前文传送门: Spring源码分析之预启动流程 Spring源码分析之BeanFactory体系结构 本文内容: AbstractApplicationContext#refresh前部分的一点小内容 ...
- Atitit main函数的ast分析 数组参数调用的ast astview解析
Atitit main函数的ast分析 数组参数调用的ast astview解析 1.1. Xxcls.main(new String[]{"","bb"}) ...
- python通过http请求发送soap报文进行webservice接口调用
最近学习Python调用webservice 接口,开始的时候主要采用suds 的方式生产client调用,后来发现公司的短信接口采用的是soap报文来调用的,然后开始了谷歌,最后采用httplib ...
- 【协议】AAA Radius协议的常用报文分析
写在前面的话 RADIUS:Remote Authentication Dial In User Service,远程用户拨号认证系统由RFC2865,RFC2866定义,是应用最广泛的AAA协议. ...
随机推荐
- java弱引用之WeakHashMap相关资料
本人博客中有一篇文章对java中的引用有详细的介绍[http://www.cnblogs.com/javaee6/p/4763190.html],java中WeakHashMap这个类就是java弱引 ...
- 【小白的CFD之旅】05 补充基础
黄师姐是一个很干脆果敢的人,从她的日常装扮就能显露出来.卡帕运动装,白色运动鞋,马尾辫,这是小白对黄师姐的第一印象.“明天早上九点钟来实验室,我给你安排这阵子的任务.”黄师姐对小白说.说话语气和老蓝一 ...
- Java公众号推荐 - BeJavaGod
今天新创建了一个java的公众号,会经常更新java的文章,有兴趣的朋友关注一下吧- 主要内容基本是跟本微博同步的 不管是做java的新手还是高手,内行还是外行,java还是非java,一起关注,一起 ...
- kettle运行spoon.bat时找不到javaw文件
我也遇到这问题了,分享一下解决方法吧以后没准还有人能用到.我机器的主要问题是环境变量JAVA_HOME的值不对,应该写到jdk也就是C:\Program Files\Java\jdk1.7.0_25, ...
- Mysql更换MyISAM存储引擎为Innodb的操作记录
一般情况下,mysql会默认提供多种存储引擎,可以通过下面的查看: 1)查看mysql是否安装了innodb插件.通过下面的命令结果可知,已经安装了innodb插件. mysql> show p ...
- JS中变量名和函数名重名
今天骚凯问了一道变量名冲突的题目,感觉很有意思,顺便也复习一下预解析的一些知识,有不对的地方忘前辈大神指正,题目是这样的: var a=100; function a(){ console.log(a ...
- 豪斯课堂K先生全套教程淘宝设计美工第一期+第四期教程(无水印)
第一期课程包括 <配色如此简单> <配色的流程><对称之美>第二期课程包括 <字体的气质及组合><平衡及构图形式><信息的筛选与图片的 ...
- 解决Firefox/Opera 不支持onselectstart事件实现不允许用户select
在IE/Safari/Chrome中我们可以使用onselectstart事件来阻止用户选定元素内文本,本文为大家解决下火狐中如何实现不能选择,由此需求的朋友可以参考下,希望对大家有所帮助 ...
- JQuery中each()的使用方法说明
JQuery中each()的使用方法说明 对于jQuery对象,只是把each方法简单的进行了委托:把jQuery对象作为第一个参数传递给jQuery的each方法.换句话说:jQuery提供的eac ...
- C#进阶系列——MEF实现设计上的“松耦合”(二)
前言:前篇 C#进阶系列——MEF实现设计上的“松耦合”(一) 介绍了下MEF的基础用法,让我们对MEF有了一个抽象的认识.当然MEF的用法可能不限于此,比如MEF的目录服务.目录筛选.重组部件等高级 ...