【问题标题】:Unable to invoke WCF service methods from Windows Phone 7 emulator无法从 Windows Phone 7 模拟器调用 WCF 服务方法
【发布时间】:2011-12-14 22:49:47
【问题描述】:

我是 WCF 新手,我正在尝试创建一个调用自托管 WCF 服务的 Windows Phone 7 应用程序。我创建了托管在控制台应用程序中的 WCF 服务。我无法从在模拟器中运行的 Windows 7 应用程序调用该服务,但我可以从 WCF 服务在同一台机器上运行的另一个客户端控制台应用程序调用它。 Windows Phone 应用程序和客户端控制台应用程序的服务调用代码和 WCF 配置文件相似。

服务配置

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="BusinessServices.ServiceA" behaviorConfiguration="serviceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://warp-core:8000"/>
          </baseAddresses>
        </host>
        <endpoint address="ServiceA" contract="BusinessServiceContracts.IServiceA" binding="basicHttpBinding"  />
        <endpoint binding="mexHttpBinding" bindingConfiguration="" name="mex" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

在 Windows Phone 7 项目中,我能够添加服务引用并生成代理类来调用服务。

Windows Phone 客户端配置

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceA" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            maxBufferSize="65536" maxReceivedMessageSize="65536" textEncoding="utf-8">
          <security mode="None" />
        </binding>
        <binding name="basicHttp" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://warp-core:8000/ServiceA" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IServiceA" contract="ServiceA.IServiceA"
          name="BasicHttpBinding_IServiceA" />
    </client>
  </system.serviceModel>
</configuration>

从电话中,如果我尝试异步调用服务

IServiceA m_proxyA;
public MainPage()
{
    InitializeComponent();

    m_proxyA = new ServiceAClient();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    IAsyncResult result = m_proxyA.BeginOperation1(Operation1Callback, null);
}

public void Operation1Callback(IAsyncResult ar)
{
    string result = m_proxyA.EndOperation1(ar);
}

我收到带有消息的 ServerTooBusyException

The HTTP service located at http://warp-core:8000/ServiceA is too busy.

如果我尝试另一种阻塞方法来调用以下服务,那么手机应用程序将挂起并且以下方法调用永远不会返回

private void button1_Click(object sender, RoutedEventArgs e)
{
    IAsyncResult result = m_proxyA.BeginOperation1(null, null);
    string output = m_proxyA.EndOperation1(result);
}

如果我从客户端控制台应用程序尝试此操作,上述两个代码示例均有效。

关于我在这里可能缺少什么的任何想法?

【问题讨论】:

    标签: wcf windows-phone-7


    【解决方案1】:

    我首先要看的是 ClientConfig 文件。它存在于您的 Windows Phone 7 项目中吗?在this post 中可以找到一些指向您的问题的指针。迈克发布了一些handy information here。您是否尝试过打开 WCF 服务上的跟踪以检查是否有任何问题?

    【讨论】:

    • 我已经阅读了您提到的帖子。启用 WCF 跟踪就可以了。我的服务配置中有多个端点,并且服务正在侦听不同的端点。更改端点的顺序使我的 WP7 客户端与 WCF 服务对话。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-28
    • 2011-08-02
    • 1970-01-01
    • 2012-11-19
    • 2013-05-09
    相关资源
    最近更新 更多