在 Silverlight 3 WCF 客户端中接收 NotFound CommunicationException

发布于 2024-08-16 21:34:31 字数 4200 浏览 2 评论 0原文

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

I'm getting a very unhelpful CommunicationException when attempting to call a WCF service from Silverlight 3. The message of the exception is "The remote server returned an error: NotFound." Each inner exception parrots that same message. Is there a problem with my setup that could be causing this issue?

Here's my setup. The WCF service is hosted in a Windows service running on the .NET 4.0 platform. It has three endpoints:

  • The main endpoint uses a pollingDuplexHttpBinding binding and has the address "DashboardService"
  • The metadata exchange endpoint uses a mexHttpBinding binding and has the address "mex"
  • The policy providing endpoint (this needs to allow cross-domain calls) uses a webHttpBinding binding and has the address "".

Here's the whole system.serviceModel section:

<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>

In the Silverlight client code, I added a service reference, and that seems to have worked just fine. And the client fetches the cross-domain policy on the service as expected. However, when I call the main DashboardService methods, I get the CommunicationException, and a breakpoint in my server-side method is never reached. Here's the Silverlight ClientConfig file generated by adding the service reference:

<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>

Are there any problems with this setup, or are there any additional things I need to do to get a polling duplex HTTP binding to work? Or do you at least know of how I can get more information about what the issue is?

Edit:

I just tried setting up the client and server bindings through code instead to see if it would help, but I still get the identical exception. Here's the server code:

var dboardService = new DashboardService();
ServiceHost host = new ServiceHost(dboardService);
host.AddServiceEndpoint(
    typeof(IDashboardService),
    new CustomBinding(
        new PollingDuplexBindingElement(),
        new BinaryMessageEncodingBindingElement(),
        new HttpTransportBindingElement()),
    "DashboardService");
host.Open();

And here's the client code:

private IDashboardService _svc = new DashboardServiceClient(
    new PollingDuplexHttpBinding(),
    new EndpointAddress("http://localhost:8732/DashboardService"));

Edit 2:

I tried changing the client code to this, but the same issue occurs:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤 2024-08-23 21:34:31

你一定是在开玩笑吧!我在标题为 Silverlight 中的网络安全访问限制

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

我的端口号更改为 4505 后,在执行来自 Silverlight 的请求。

You've gotta be kidding me! I found the reason why this wasn't working in an MSDN article titled Network Security Access Restrictions in Silverlight:

One additional restriction on using the sockets classes is that the destination port range that a network application is allowed to connect to must be within the range of 4502-4534."

After changing my port number to 4505, the server code was reached after making a request from Silverlight.

子栖 2024-08-23 21:34:31

尝试通过代码创建端点,与您现在所做的方式完全相同。
但在客户端像这样创建代理。

CustomBinding binding = new CustomBinding(
                new PollingDuplexBindingElement(),
                new BinaryMessageEncodingBindingElement(),
                new HttpTransportBindingElement());


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

try creating the endpoint through code, exactly the same way you're doing it now.
But on the client side create the proxy like so.

CustomBinding binding = new CustomBinding(
                new PollingDuplexBindingElement(),
                new BinaryMessageEncodingBindingElement(),
                new HttpTransportBindingElement());


private IDashboardService _svc = new DashboardServiceClient(binding,
   new EndpointAddress("http://localhost:8732/DashboardService"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文