在WCF使用SOAP1.1

      如果要在WCF中使用SOAP1.1.,使用basicHttpBinding可以很容易实现,basicHttpBinding默认使用SOAP1.1.。利用自带的例子配置binding为basicHttpBinding:

 1:  <?xml version="1.0"?>
 2:  <configuration>
 3:   <system.web>
 4:      <compilation debug="true" targetFramework="4.0" />
 5:    </system.web>
 6:    <system.serviceModel>
 7:       <behaviors>
 8:        <serviceBehaviors>
 9:          <behavior name="WcfService1.Service1Behavior">
10:            <serviceMetadata httpGetEnabled="true"/>
11:            <serviceDebug includeExceptionDetailInFaults="false"/>
12:          </behavior>
13:        </serviceBehaviors>
14:      </behaviors>
15:      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
16:        <services>
17:            <service behaviorConfiguration="WcfService1.Service1Behavior"
18:                name="WcfService1.Service1">
19:                <endpoint address="" binding="basicHttpBinding"
20:                    contract="WcfService1.IService1">
21:                    <identity>
22:                        <dns value="localhost" />
23:                    </identity>
24:                </endpoint>
25:            </service>
26:        </services>
27:    </system.serviceModel>
28:   <system.webServer>
29:      <modules runAllManagedModulesForAllRequests="true"/>
30:    </system.webServer>
31:  </configuration>
32:  
33:  

       客户端引用WCF,代码:

1:  static void Main(string[] args)
2:  {
3:      localhost.Service1Client client = new localhost.Service1Client();
4:      client.GetData(1);
5:  }
6:   

       利用tcpTrace截包,使用basicHttpBinding截包数据:

image

      可以看出使用的是SOAP1.1(SOAP1.1有SOAPAction项,SOAP1.2没有,当然SOAP1.2和1.1还有其他的区别,具有请查看w3的文档)。

 

      wsHttpBinding默认使用SOAP1.2(确切应该是Soap12WSAddressing10),修改配置文件:

 1:  <?xml version="1.0"?>
 2:  <configuration>
 3:   <system.web>
 4:      <compilation debug="true" targetFramework="4.0" />
 5:    </system.web>
 6:    <system.serviceModel>
 7:       <behaviors>
 8:        <serviceBehaviors>
 9:          <behavior name="WcfService1.Service1Behavior">
10:            <serviceMetadata httpGetEnabled="true"/>
11:            <serviceDebug includeExceptionDetailInFaults="false"/>
12:          </behavior>
13:        </serviceBehaviors>
14:      </behaviors>
15:      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
16:        <services>
17:            <service behaviorConfiguration="WcfService1.Service1Behavior"
18:                name="WcfService1.Service1">
19:                <endpoint address="" binding="wsHttpBinding"
20:                    contract="WcfService1.IService1">
21:                    <identity>
22:                        <dns value="localhost" />
23:                    </identity>
24:                </endpoint>
25:            </service>
26:        </services>
27:    </system.serviceModel>
28:   <system.webServer>
29:      <modules runAllManagedModulesForAllRequests="true"/>
30:    </system.webServer>
31:  </configuration>
32:  
33:  

       使用wsHttpBinding截包数据:

image

       wsHttpBinding默认是使用Message的传输方式。

image

        basicHttpBinding默认是使用soap1.1,但是basicHttpBinding是明文传输的,wsHttpBinding可以实现加密传输,但soap是soap1.2;可以利用自定义绑定(customBinding)设置soap版本为soap1.1,并且使用加密等传输方式:

 1:  <?xml version="1.0"?>
 2:  <configuration>
 3:   <system.web>
 4:      <compilation debug="true" targetFramework="4.0" />
 5:    </system.web>
 6:    <system.serviceModel>
 7:       <behaviors>
 8:        <serviceBehaviors>
 9:          <behavior name="WcfService1.Service1Behavior">
10:            <serviceMetadata httpGetEnabled="true"/>
11:            <serviceDebug includeExceptionDetailInFaults="false"/>
12:          </behavior>
13:        </serviceBehaviors>
14:      </behaviors>
15:      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
16:        <services>
17:            <service behaviorConfiguration="WcfService1.Service1Behavior"
18:                name="WcfService1.Service1">
19:                <endpoint address="" binding="customBinding" bindingConfiguration="Soap11AddressingBinding"
20:                    contract="WcfService1.IService1">
21:                    <identity>
22:                        <dns value="localhost" />
23:                    </identity>
24:                </endpoint>
25:            </service>
26:        </services>
27:        <bindings>
28:            <customBinding>
29:                <binding name="Soap11AddressingBinding">
30:                    <textMessageEncoding messageVersion="Soap11WSAddressing10" />
31:                    <httpTransport/>
32:                </binding>
33:            </customBinding>
34:        </bindings>
35:    </system.serviceModel>
36:   <system.webServer>
37:      <modules runAllManagedModulesForAllRequests="true"/>
38:    </system.webServer>
39:  </configuration>
40:  
41:  

        使用Soap11AddressBinding截包数据:

image

posted @ 2010-10-18 23:10  Asharp  阅读(6168)  评论(0编辑  收藏  举报