basicHttpBinding,MEX,SOAP
一、WCF服务
WCF服务有两种方案可以发布自己的元数据。一种是基于HTTP-GET协议提供元数据;另一种则为MEX终结点元数据交换方式,和WCF服务一样使用一个专门的终结点,称为MEX元数据交换终结点。
《basicHttpBinding,HTTP-GET,SOAP》采用HTTP-GET协议提供元数据,本文采用MEX终结点的方式提供。
配置文件
1 <?xmlversion="1.0"encoding="utf-8" ?> 2 <configuration> 3 <system.serviceModel> 4 <behaviors> 5 <serviceBehaviors> 6 <behavior name="metadataBehavior"> 7 <serviceMetadata /> 8 </behavior> 9 </serviceBehaviors> 10 </behaviors> 11 <services> 12 <service behaviorConfiguration="metadataBehavior" name="testwcf.serviers.httpsoap"> 13 <host> 14 <baseAddresses> 15 <add baseAddress="http://localhost:8733/httpsoap"/> 16 </baseAddresses> 17 </host> 18 <endpoint address="" binding="basicHttpBinding" contract="testwcf.serviers.Ihttpsoap" /> 19 <endpoint address="mex" binding="mexHttpBinding“ contract="IMetadataExchange" /> 20 </service> 21 </services> 22 </system.serviceModel> 23 24 </configuration>
二、加载服务
使用WCF Test Client加载http://leiwangs-pc:8733/httpsoap/mex, 截获了一条数据:
Request(RAW):
1 POST http://leiwangs-pc:8733/httpsoap/mex HTTP/1.1 2 Content-Type: application/soap+xml; charset=utf-8 3 Host: leiwangs-pc:8733 4 Content-Length: 478 5 Expect: 100-continue 6 Accept-Encoding: gzip, deflate 7 Connection: Keep-Alive 8 9 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 10 <s:Header> 11 <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action> 12 <a:MessageID>urn:uuid:44747df6-8c5d-485a-a688-3ecd236021da</a:MessageID> 13 <a:ReplyTo> 14 <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 15 </a:ReplyTo> 16 <a:To s:mustUnderstand="1">http://leiwangs-pc:8733/httpsoap/mex</a:To> 17 </s:Header> 18 <s:Body/> 19 </s:Envelope>
Response(RAW):Header
1 HTTP/1.1 200 OK 2 Content-Length: 6025 3 Content-Type: application/soap+xml; charset=utf-8 4 Server: Microsoft-HTTPAPI/2.0 5 Date: Thu, 11 Apr 2013 06:14:34 GMT
Response(RAW):Content
可以看出,响应为SOAP格式的数据,它的Related to与Request的MessageID是相同的,它的元数据包含在SOAP消息的Body里。展开可以看到第一个结点与《Fiddler下的WCF——basicHttpBinding,HTTP-GET,SOAP》中使用HTTP-GET方式获取的元数据完全一致,第二个和第三个结点可以与http://localhost:8733/httpsoap?xsd=xsd0和http://localhost:8733/httpsoap?xsd=xsd1对应。包含数据一致,组织结构不一样。
三、调用服务提供的方法
与《basicHttpBinding,HTTP-GET,SOAP》一致,它们之间的区别仅仅在于元数据提供的方式不同。
两种元数据的区别请参见《元数据WSDL vs Mex》。