2012-01-23 48 views
0

我有一個帶有customBinding端點的WCF服務。添加服務引用時,WCF customBinding是BasicHTTPBinding

<customBinding> 
    <binding name="customBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"> 
     <binaryMessageEncoding> 
     <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" /> 
     </binaryMessageEncoding> 
     <httpTransport maxReceivedMessageSize="40194304" /> 
    </binding> 
    </customBinding>  

我的服務是:

<services> 
    <service name="Test2"> 
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding" contract="MyServiceContract.ContractInterface"> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 

然而,在我的客戶端應用程序,每當我添加一個服務引用,產生的參考值是basicHttpBinding的(在app.config)中

能有什麼我確實要「強制」客戶端使用自定義綁定?

感謝 亞歷克斯

回答

1

服務沒有使用你指定的綁定。我的猜測是服務名實際上是「MyServiceContract.Test2」(或類似的東西)而不是「Test2」,所以當WCF沒有找到與服務類匹配的<service>元素時,它只使用默認端點,恰好使用basicHttpBinding

1

您是否爲自定義綁定(從System.ServiceModel.Channels.Binding派生的類)定義了一個類?

如果是這樣,你有沒有添加新的綁定到配置綁定擴展?

<extensions> 
    <bindingExtensions> 
    <add name="myCustomeBinding" type="MyCustomeBinding, MyCustomeBindingLibrary" /> 
    </bindingExtensions> 
</extensions> 

綁定的工作是定義創建WCF通道的「配方」。基本上配方由一系列綁定元素組成。

哪些綁定您在配方中選擇的元素決定了WCF頻道將執行的通信的性質。

在絕對最低的綁定元素的配方需要包括:

  • 郵件編碼(文/二進制等)
  • 運輸(HTTP/TCP等)

如果你不沒有定義綁定的類,WCF沒有別的選擇,只能根據這兩個綁定元素的默認值創建一個通道,所以當沒有綁定定義時可能會設計爲切換到basicHttpBinding。

這將是我的猜測。

相關問題