![](/img/trans.png)
[英]Custom Endpoint Behavior not being used in WCF Client with Service Reference
[英]WCF service reference not including binding and client endpoint
我正在從另一個問題中獲得答案 ,試圖使我的WCF服務僅處理GET請求。 我已經將[WebGet]
添加到了操作中,並使用<webHttp />
添加了端點行為,將默認端點更改為使用上述行為,並將默認端點的綁定更改為webHttpBinding
。
web.config的system.servicemodel看起來像:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="TestServiceLibrary.TestService">
<endpoint behaviorConfiguration="webBehavior"
address=""
binding="webHttpBinding"
contract="TestServiceLibrary.ITestService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
這使我的服務可以調用,例如: TestService.svc/GetData?value=x
,效果很好。 現在,我想向客戶項目添加服務引用。 當我這樣做時,客戶端項目的app.config文件未獲取綁定和客戶端端點的配置。 如果刪除上面的行為webBehavior
,請將默認的終結點綁定更改回wsHttpBinding
,然后重新添加客戶端的服務引用-成功添加了客戶端綁定和終結點,但是我失去了GET支持。
我意識到我可以使用wsHttpBinding
保留默認終結點,並添加一個設置了不同地址的終結點來綁定webHttpBinding
並使用<webHttp />
進行行為,但是我真的希望客戶端應用程序使用GET。
編輯:
我也對為什么在這種情況下無法更新配置感興趣。 我想讓這項服務的使用量降低(通過Visual Studio添加服務參考,然后開始進行調用),因此手動設置客戶端配置文件不是理想的選擇。
請嘗試以下配置。 我沒有測試過,但是應該可以正常工作。 另外,我建議您使用此示例自己動手做客戶。 請注意, ISampleService
接口(在您的情況下為TestServiceLibrary.ITestService
)和此接口引用的所有數據合同應放在單獨的程序集中,服務和客戶端均將其引用為dll。
<system.serviceModel>
<client>
<endpoint behaviorConfiguration="webBehavior" address="url_to_TestService.svc" binding="webHttpBinding" contract="TestServiceLibrary.ITestService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.