【发布时间】:2012-03-24 19:08:49
【问题描述】:
我在托管 Windows 服务中开发了一个 WCF,基于此 tutorial
这就是我的界面的定义方式:
namespace HomeAutomationWindowsService
{
[ServiceContract]
public interface IHomeAutomation
{
[OperationContract]
string connect();
[OperationContract]
Boolean sendAction(string address, string command);
}
}
而我的 App.config 文件是这样的:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Unsecured">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="HomeAutomationWindowsService.HomeAutomationService"
behaviorConfiguration="HomeAutomationServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://192.168.11.178:8000/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/service -->
<endpoint address=""
contract="HomeAutomationWindowsService.IHomeAutomation"
binding="wsHttpBinding"
bindingConfiguration="Unsecured" />
<!-- the mex endpoint is explosed at http://192.168.11.178:8000/ mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HomeAutomationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
当我从控制台或 WPF 应用程序拨打电话时,我可以看到公共方法,但当我使用 Windows Phone 拨打电话时,我什么都看不到。
我应该怎么做才能让我的 WCF 或 Windows Phone 一起通信。
【问题讨论】:
-
您是否尝试过添加服务参考?查看这篇文章:eliasmarkelis.wordpress.com/2011/02/27/windows-phone-7-with-wcf
-
您是否在服务端添加了 CrossDomainPolicy 文件?
-
在 Desktop Silverlight 中,您需要一个文件来指定您可以访问该服务。它被称为 clientaccesspolicy.xml 并且需要在域的根目录中。也许这种行为是继承到 Windows Phone 的。
-
@DmitriyReznik 我做到了,我可以实例化a服务,只是我无法访问公共功能。
-
@VitorCanova 我发现使用 Silverlight 的人也有同样的问题,我正在尝试看看我能解决这个问题。
标签: c# wcf visual-studio windows-phone-7 sdk