2011-06-25 61 views
2

我需要通過WCF服務傳遞超過64kb的數據。要做到這一點我已經配置了服務器端(託管WCF服務)的方式如下:通過WCF服務傳輸大量數據(超過64kb)

<services> 
    <service name="MyService" behaviorConfiguration="MyServiceBehavior" > 
    <endpoint address="" binding="customBinding" contract="MyContract" 
     bindingName="testBinding" bindingConfiguration="testBinding" /> 
    <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" 
     bindingName="testBinding" bindingConfiguration="testBinding" /> 
    </service> 
</services> 

<bindings> 
    <customBinding> 
    <binding name="testBinding" > 
     <textMessageEncoding> 
     <readerQuotas maxDepth="2147483647" 
      maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
     </textMessageEncoding> 
     <httpTransport transferMode="Buffered" 
     maxReceivedMessageSize="2147483647" 
     maxBufferSize="2147483647"/> 
    </binding> 
    </customBinding> 
</bindings> 

和客戶端(即消費服務):

<client> 
    <endpoint address="http://localhost:82/MyService.svc" 
    binding="customBinding" bindingConfiguration="testBinding" 
    contract="MyContract" 
    name="MyName" /> 
</client> 

<bindings> 
    <customBinding> 
    <binding name="testBinding" > 
     <textMessageEncoding> 
     <readerQuotas maxDepth="2147483647" 
      maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
     </textMessageEncoding> 
     <httpTransport transferMode="Buffered" 
     maxReceivedMessageSize="2147483647" 
     maxBufferSize="2147483647"/> 
    </binding> 
    </customBinding> 
</bindings> 

當我打電話要求的方法我已收到以下錯誤:

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:82/MyService.svc . The client and service bindings may be mismatched.

請指教,什麼是我的綁定不匹配?

謝謝。

回答

2

看起來像你做了太多太多的事情 - 太複雜了。你爲什麼不使用基於現有綁定的綁定配置?像這樣:

<bindings> 
    <basicHttpBinding> 
    <binding name="largeBinding" 
      maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <readerQuotas 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" /> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<services> 
    <service name="MyService" behaviorConfiguration="MyServiceBehavior" > 
    <endpoint 
     address="" 
     binding="basicHttpBinding" 
     bindingConfiguration="largeBinding" 
     contract="MyContract" /> 
    <endpoint 
     address="mex" 
     binding="mexHttpBinding" 
     contract="IMetadataExchange" /> 
    </service> 
</services> 

在客戶端定義完全相同的綁定配置,並在那裏使用它。

此外,您MEX終結元數據交換應該NEVER有任何特殊設置 - 只使用默認mexHttpBinding,不配置任何綁定配置。

+0

事實上,如果您願意將元數據作爲WSDL提供服務,則根本不需要mex端點 - 只需在serviceMetadata行爲中設置httpGetEnabled = true(可能還有httpGetUrl,如果您沒有基地址) –

0

確保服務器配置文件中的服務名稱與服務的完全限定名稱匹配 - <system.serviceModel/services/service>元素中的名稱屬性。如果它不匹配,那麼WCF將提供一個默認端點,其綁定爲basicHttpBinding(並且它所期望的內容類型與客戶端發送的內容類型不同)。

+0

這不是一個案例。謝謝。 – Budda