无法从Windows Phone 7模拟器调用WCF服务方法

时间:2010-09-01 10:52:42

标签: wcf windows-phone-7

我是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);
}

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

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

1 个答案:

答案 0 :(得分:0)

我要看的第一项是ClientConfig文件。它存在于您的Windows Phone 7项目中吗?您可以在this post中找到有关您的问题的一些提示。迈克发布了一些handy information here。您是否尝试在WCF服务上启用跟踪以检查是否存在任何问题?