gpt4 book ai didi

c# - 在 Windows Phone Mango 中启用 WCF 调用

转载 作者:太空宇宙 更新时间:2023-11-03 16:33:53 27 4
gpt4 key购买 nike

我基于此 tutorial 在托管 Windows 服务中开发了一个 WCF

我的界面是这样定义的:

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 应用程序进行调用时,我可以看到公共(public)方法,但是当我使用 Windows Phone 进行调用时,我看不到任何东西。

我应该怎么做才能让我的 WCF 或 Windows Phone 一起通信。

最佳答案

我认为 WP7 不支持 WsHttpBinding。尝试使用 BasicHttpBinding:

网络配置:

  <system.serviceModel>
<services>
<service name="MyProject.MyService" behaviorConfiguration="behavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="binding" contract="MyProject.MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="binding">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>

将网络服务添加到您的 WP7 项目(添加服务引用)后,ServiceReferences.ClientConfig 应该如下所示(使用 WsHttpBinding 添加网络服务会生成一个空文件):

<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44300/Services/DataService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
contract="DataService.DataService" name="BasicHttpBinding_DataService" />
</client>
</system.serviceModel>
</configuration>

关于c# - 在 Windows Phone Mango 中启用 WCF 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9854652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com