2014-04-10 18 views

回答

2

可以爲不同的應用程序使用相同的WCF服務。 爲同一WCF服務創建多個綁定和多個端點

多個綁定

<bindings> 
    <netTcpBinding> 
    <binding name="netTcpBindingConfiguration" receiveTimeout="infinite" sendTimeout="10.00:00:00" maxBufferPoolSize="1073741824" maxBufferSize="1073741824" maxReceivedMessageSize="1073741824"> 
     <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
    </binding> 
    </netTcpBinding> 
    <webHttpBinding> 
    <binding name="webHttpBindingConfiguration" receiveTimeout="00:10:00" sendTimeout="10.00:00:00" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824"> 
     <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
    </binding> 
    </webHttpBinding> 
</bindings> 

多個端點 - 兩個端點被曝光,一個使用的WebHttpBinding,另一個使用NetTcpBinding的

請注意,雖然在en dpoints,即使用behaviorConfiguration =「EndpointBehavior」。使用webHttpBinding的終端通過JSON公開數據。

<services> 
    <service behaviorConfiguration="behavior" name="WCFCallbackTry.Service1"> 
    <endpoint address="http://localhost:8018/Service1.svc" bindingConfiguration="webHttpBindingConfiguration" binding="webHttpBinding" 
     contract="WCFCallbackTry.IService" name="HttpEndPoint" behaviorConfiguration="EndpointBehavior"/> 
    <endpoint address="net.tcp://localhost:8004/Service1.svc" bindingConfiguration="netTcpBindingConfiguration" binding="netTcpBinding" 
     contract="WCFCallbackTry.IService" name="NetTcpEndPoint"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8018/Service1.svc"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

對於使用Jquery公開WCF,必須使用以下行爲,如您引用的鏈接所示。

<endpointBehaviors> 
<behavior name="EndpointBehavior"> 
<webHttp/> 
</behavior> 

使用NetTcpBinding的端點可以從使用C#,而可能的WebHttpBinding使用JQuery使用的客戶端應用程序來使用。

與上面類似的配置可以用於不同或相同類型的綁定,同時暴露不同的端點。

希望這會有幫助

+0

thnx dera這幫了很多.. – faraaz

相關問題