【发布时间】:2011-03-09 22:13:24
【问题描述】:
我有一个 WCF 服务,我正在尝试使用 wcf、旧肥皂和普通 xml。该服务名为 TestService.svc,配置如下所示:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="poxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TestServiceBehavior" name="TestService">
<endpoint address="" binding="wsHttpBinding" contract="ITestService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
<endpoint address="xml" binding="webHttpBinding" behaviorConfiguration="poxBehavior" contract="ITestService"/>
</service>
</services>
</system.serviceModel>
我从另一个问题中得到了这段代码: REST / SOAP endpoints for a WCF service
现在,XML webHttpBinding 似乎运行良好,但 wsHttpBinding 和 basicHttpBinding 运行不佳。
我可以使用以下方式浏览服务: http://localhost:8295/WCFTest/TestService.svc
我还可以使用该端点在 asp.net 网站项目中添加服务引用并尝试使用该服务,但是当我创建客户端时:
TestService.TestServiceClient mytest = new TestService.TestServiceClient();
它说由于多个端点而指定一个端点。我猜是因为同时拥有 wsHttp 和 basicHttp?如何在此处指定端点?
接下来,我尝试通过将 Web 引用(不是服务引用)添加到 .net 2.0 网站来使用 basicHttpBinding 端点。此时我无法添加引用并收到错误 400。
接下来我删除了 wsHttp 绑定,并能够添加 Web 引用并通过 .net 2.0 客户端使用服务。
如何配置它,以便我可以将 wsHttpBinding 用于可以使用普通 WCF 服务的客户端,将 basicHttpBinding 用于只能使用较旧的非 WCF SOAP 请求的客户端,并且仍然可以为想要使用纯 xml 的客户端使用 webHttpBinding?
【问题讨论】:
-
我认为 codemeit.com/wcf/wcf-restful-pox-json-and-soap-coexist.html 应该可以帮助您度过难关。试一试。
标签: wcf-binding