您的位置:首页 > 其它

在WCF使用SOAP1.1

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

<?xmlversion="1.0"?>

<configuration>

<system.web>

<compilationdebug="true"targetFramework="4.0"/>

</system.web>

<system.serviceModel>

<behaviors>

<serviceBehaviors>

<behaviorname="WcfService1.Service1Behavior">

<serviceMetadatahttpGetEnabled="true"/>

<serviceDebugincludeExceptionDetailInFaults="false"/>

</behavior>

</serviceBehaviors>

</behaviors>

<serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"/>

<services>

<servicebehaviorConfiguration="WcfService1.Service1Behavior"

name="WcfService1.Service1">

<endpointaddress=""binding="basicHttpBinding"

contract="WcfService1.IService1">

<identity>

<dnsvalue="localhost"/>

</identity>

</endpoint>

</service>

</services>

</system.serviceModel>

<system.webServer>

<modulesrunAllManagedModulesForAllRequests="true"/>

</system.webServer>

</configuration>




客户端引用WCF,代码:

staticvoidMain(string[]args)

{

localhost.Service1Clientclient=newlocalhost.Service1Client();

client.GetData(1);

}



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





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

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

<?xmlversion="1.0"?>

<configuration>

<system.web>

<compilationdebug="true"targetFramework="4.0"/>

</system.web>

<system.serviceModel>

<behaviors>

<serviceBehaviors>

<behaviorname="WcfService1.Service1Behavior">

<serviceMetadatahttpGetEnabled="true"/>

<serviceDebugincludeExceptionDetailInFaults="false"/>

</behavior>

</serviceBehaviors>

</behaviors>

<serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"/>

<services>

<servicebehaviorConfiguration="WcfService1.Service1Behavior"

name="WcfService1.Service1">

<endpointaddress=""binding="wsHttpBinding"

contract="WcfService1.IService1">

<identity>

<dnsvalue="localhost"/>

</identity>

</endpoint>

</service>

</services>

</system.serviceModel>

<system.webServer>

<modulesrunAllManagedModulesForAllRequests="true"/>

</system.webServer>

</configuration>




使用wsHttpBinding截包数据:





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





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

<?xmlversion="1.0"?>

<configuration>

<system.web>

<compilationdebug="true"targetFramework="4.0"/>

</system.web>

<system.serviceModel>

<behaviors>

<serviceBehaviors>

<behaviorname="WcfService1.Service1Behavior">

<serviceMetadatahttpGetEnabled="true"/>

<serviceDebugincludeExceptionDetailInFaults="false"/>

</behavior>

</serviceBehaviors>

</behaviors>

<serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"/>

<services>

<servicebehaviorConfiguration="WcfService1.Service1Behavior"

name="WcfService1.Service1">

<endpointaddress=""binding="customBinding"bindingConfiguration="Soap11AddressingBinding"

contract="WcfService1.IService1">

<identity>

<dnsvalue="localhost"/>

</identity>

</endpoint>

</service>

</services>

<bindings>

<customBinding>

<bindingname="Soap11AddressingBinding">

<textMessageEncodingmessageVersion="Soap11WSAddressing10"/>

<httpTransport/>

</binding>

</customBinding>

</bindings>

</system.serviceModel>

<system.webServer>

<modulesrunAllManagedModulesForAllRequests="true"/>

</system.webServer>

</configuration>




使用Soap11AddressBinding截包数据:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: