【问题标题】:Receiving NotFound CommunicationException in Silverlight 3 WCF client在 Silverlight 3 WCF 客户端中接收 NotFound CommunicationException
【发布时间】:2009-12-31 21:20:31
【问题描述】:

尝试从 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"));

【问题讨论】:

    标签: wcf silverlight silverlight-3.0 .net-4.0 pollingduplexhttpbinding


    【解决方案1】:

    你一定是在开玩笑吧!我在一篇名为 Network Security Access Restrictions in Silverlight 的 MSDN 文章中找到了这不起作用的原因:

    使用套接字类的另一个限制是允许网络应用程序连接的目标端口范围必须在 4502-4534 范围内。"

    将我的端口号更改为 4505 后,从 Silverlight 发出请求后到达服务器代码。

    【讨论】:

    • ive 为我的应用程序使用了端口 8080 - 8085,它可以工作,从技术上讲,你没有使用 System.Net.Sockets(仅限于端口 4502-4534),而是 HTTP,我认为问题在别处,你应该在它再次出现之前弄清楚
    • 在使用纯 HTTP 时,我也能够使用更广泛的套接字。但这是我第一次尝试使用pollingDuplexHttpBinding。我很确定更改端口号是我在开始工作之前所做的唯一修改,所以也许限制确实适用于该绑定。您之前是否在双工 HTTP 绑定中使用过更高的端口号?
    • @Neil:您的 XAP 文件是否有机会从端口 8080-8085 上的同一 http 服务器传送? XAP 源自的端口没有限制,从 XAP 到该端口上的服务器的任何其他 HTTP 访问都将被视为同站点访问。
    【解决方案2】:

    尝试通过代码创建端点,就像你现在做的那样。 但是在客户端创建这样的代理。

    CustomBinding binding = new CustomBinding(
                    new PollingDuplexBindingElement(),
                    new BinaryMessageEncodingBindingElement(),
                    new HttpTransportBindingElement());
    
    
    private IDashboardService _svc = new DashboardServiceClient(binding,
       new EndpointAddress("http://localhost:8732/DashboardService"));
    

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多