【发布时间】:2014-04-03 22:12:41
【问题描述】:
我从另一个问题关注这个answer,试图让我的 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添加服务引用,然后开始调用),所以手动设置客户端配置文件并不理想。
【问题讨论】:
标签: c# web-services wcf