我只實作了一個非常基本的 WCF 服務,我希望客戶端在其配置中自動生成一些屬性,例如 maxReceivedMessageSize、maxBufferSize 等(默認的 maxReceivedMessageSize 對我來說還不夠)。我在服務應用程式的 web.config 檔案中有以下配置。我有正確配置的系結(BasicHttpBinding_IService1_YY),該系結在服務端點和客戶端端點中都被參考(我不確定是否也需要客戶端端點)。我在服務下也有 mexHttpBinding 型別的端點。該服務指向 httpGetEnabled 為 true 的行為。畢竟,當我由此生成客戶端時,系結引數將不存在,它將使用默認值。自然地,wsdl 不包含這些引數。
所以我的問題是這是否超出了 WCF 的范圍?如果有變化,我是否必須從這個角度手動維護客戶端配置?這個問題有沒有解決方案,因為我瀏覽了很多stackoverflow和其他主題,一無所獲,或者我很粗心。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" httpGetBindingConfiguration="BasicHttpBinding_IService1_YY" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfServiceApplication.Service1" behaviorConfiguration="myServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:51483/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceApplication.IService1"
bindingConfiguration="BasicHttpBinding_IService1_YY" name="BasicHttpBinding_IService1_YY" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" >
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1_YY"
maxReceivedMessageSize="20000099" maxBufferSize="20000099" maxBufferPoolSize="20000099"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1_YY" contract="WcfServiceApplication.IService1"
name="BasicHttpBinding_IService1_YY" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
以及生成的客戶端配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1_YY" sendTimeout="00:05:00" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:51483/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1_YY" contract="IService1"
name="BasicHttpBinding_IService1_YY" />
</client>
</system.serviceModel>
</configuration>
好的,系結的名稱確實顯示正確,但僅此而已。當我手動調整它時,一切正常,但我認為應該有更合適的解決方案。
你能幫我解決這個問題嗎?提前致謝。
uj5u.com熱心網友回復:
答案大概是:是的。
WCF的特點是客戶端和服務器可以分開演進。服務器設定不會自動更新到客戶端,需要在客戶端手動設定需要的引數。
您可以嘗試使用“更新服務參考”功能進行更新,而不是創建新的服務參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/515456.html
