WCF多協議支援

來源:互聯網
上載者:User

開篇:

最近工作中使用WCF比較多,有了一點收穫,也有了一點淺薄的想法,在此寫出,希望能給大家帶來一些收穫。

 

本章說明:

實際開發中可能會出現,一個服務端需應付多個不同協議用戶端,下文就是這種情境的一個解決方案。

 

Binding所對應的協議版本:

Binding Class Name

Transport

Message Encoding

Message Version

Security Mode

Reliable Messaging

Transaction Flow (disabled by default)

Example Application?

BasicHttpBinding

HTTP

Text

SOAP 1.1

None

Not Supported

Not Supported

?

WSHttpBinding

HTTP

Text

SOAP 1.2 WS-Addressing 1.0

Message

Disabled

WS-AtomicTransactions

?

WSDualHttpBinding

HTTP

Text

SOAP 1.2 WS-Addressing 1.0

Message

Enabled

WS-AtomicTransactions

?

WSFederationHttpBinding

HTTP

Text

SOAP 1.2 WS-Addressing 1.0

Message

Disabled

WS-AtomicTransactions

?

NetTcpBinding

TCP

Binary

SOAP 1.2

Transport

Disabled

OleTransactions

?

NetPeerTcpBinding

P2P

Binary

SOAP 1.2

Transport

Not Supported

Not Supported

?

NetNamedPipesBinding

Named Pipes

Binary

SOAP 1.2

Transport

Not Supported

OleTransactions

?

NetMsmqBinding

MSMQ

Binary

SOAP 1.2

Message

Not Supported

Not Supported

?

MsmqIntegrationBinding

MSMQ

Not Supported (uses a pre-WCF serialization   format)

Not Supported

Transport

Not Supported

Not Supported

?

CustomBinding

You Decide

You Decide

You Decide

You Decide

You Decide

You Decide

?

 

服務端配置:

Server

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.web>    <compilation debug="true" targetFramework="4.0" />  </system.web>  <system.serviceModel>    <bindings>      <wsHttpBinding>        <binding name="wsHttpBindingConfiguration" maxReceivedMessageSize="2147483647">          <security mode="None">          </security>        </binding>      </wsHttpBinding>      <basicHttpBinding>        <binding name="basicHttpBindingConfiguration" maxReceivedMessageSize="2147483647">          <security mode="None">          </security>        </binding>      </basicHttpBinding>    </bindings>    <behaviors>      <serviceBehaviors>        <behavior name="behaviorConfiguration">          <serviceDebug includeExceptionDetailInFaults="true"  />          <serviceMetadata httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" httpGetEnabled="true" />          <serviceThrottling maxConcurrentSessions="10000"  maxConcurrentInstances="10000" maxConcurrentCalls="10000" />        </behavior>      </serviceBehaviors>    </behaviors>    <services>      <service behaviorConfiguration="behaviorConfiguration" name="WcfServer.UserService" >        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" contract="WcfServer.IUserService" />        <endpoint address="soap11" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration"  contract="WcfServer.IUserService" />        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />      </service>    </services>  </system.serviceModel>  <system.webServer>    <modules runAllManagedModulesForAllRequests="true"/>  </system.webServer></configuration>

 

用戶端配置:

Client

<?xml version="1.0" encoding="utf-8" ?><configuration>  <system.serviceModel>    <bindings>      <wsHttpBinding>        <binding name="wsHttpBindingConfiguration" >          <security mode="None">          </security>        </binding>      </wsHttpBinding>      <basicHttpBinding>        <binding name="basicHttpBindingConfiguration">          <security mode="None">          </security>        </binding>      </basicHttpBinding>    </bindings>    <client>      <endpoint address="http://localhost/WcfServer/UserService.svc"        binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration"        contract="WcfServer.IUserService" name="UserService">        <identity>          <dns value="localhost" />        </identity>      </endpoint>      <endpoint address="http://localhost/WcfServer/UserService.svc/Soap11"        binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration"        contract="WcfServer.IUserService" name="UserServiceSoap11">        <identity>          <dns value="localhost" />        </identity>      </endpoint>    </client>  </system.serviceModel></configuration>

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.