尝试从 Silverlight 3 调用 WCF 服务时,我收到一个非常无用的 CommunicationException。异常消息是“远程服务器返回错误:NotFound”。每个内部异常都会复制相同的消息。我的设置是否存在可能导致此问题的问题?
这是我的设置。WCF 服务托管在 .NET 4.0 平台上运行的 Windows 服务中。它具有三个端点:
- 主端点使用 pollingDuplexHttpBinding 绑定,地址为“DashboardService”
- 元数据交换端点使用 mexHttpBinding 绑定,地址为“mex”
- 策略提供端点(这需要允许跨域调用)使用 webHttpBinding 绑定并具有地址“”。
这是整个 system.serviceModel 部分:
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="PolicyProviderBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="RoboTrader.TheFloor.DashboardService">
<endpoint address="" binding="webHttpBinding"
behaviorConfiguration="PolicyProviderBehavior"
contract="RoboTrader.DashboardService.IPolicyProvider"/>
<endpoint address="DashboardService" binding="pollingDuplexHttpBinding"
contract="RoboTrader.DashboardService.IDashboardService"/>
<endpoint address="DashboardService/mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
在 Silverlight 客户端代码中,我添加了一个服务引用,这似乎工作得很好。并且客户端按预期获取服务上的跨域策略。但是,当我调用主要的 DashboardService 方法时,我得到了 CommunicationException,并且永远不会到达我的服务器端方法中的断点。这是通过添加服务引用生成的 Silverlight ClientConfig 文件:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="PollingDuplexHttpBinding_IDashboardService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/DashboardService"
binding="customBinding"
bindingConfiguration="PollingDuplexHttpBinding_IDashboardService"
contract="Service.IDashboardService"
name="PollingDuplexHttpBinding_IDashboardService" />
</client>
</system.serviceModel>
此设置是否有任何问题,或者我需要做任何其他事情才能使轮询双工 HTTP 绑定正常工作?或者您至少知道我如何获得有关问题所在的更多信息吗?
编辑:
我只是尝试通过代码设置客户端和服务器绑定,而不是查看它是否有帮助,但我仍然得到相同的异常。这是服务器代码:
var dboardService = new DashboardService();
ServiceHost host = new ServiceHost(dboardService);
host.AddServiceEndpoint(
typeof(IDashboardService),
new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
"DashboardService");
host.Open();
这是客户端代码:
private IDashboardService _svc = new DashboardServiceClient(
new PollingDuplexHttpBinding(),
new EndpointAddress("http://localhost:8732/DashboardService"));
编辑2:
我尝试将客户端代码更改为此,但出现同样的问题:
private IDashboardService _svc = new DashboardServiceClient(
new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
new EndpointAddress("http://localhost:8732/DashboardService"));