【发布时间】: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