WCF Service in windows phone 7

本文关键字:phone windows in Service WCF | 更新日期: 2023-09-27 18:13:52

我有一个连接WCF服务和Windows Phone的问题。我有一个没有源代码的服务(只在网络上发布),我需要在Windows Phone 7应用程序中使用它。

我在项目中添加了一个服务引用,VS生成了一个文件ServiceReferences。ClientConfig:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpBinding_IWcfMobilServices">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.www.com/WcfMobilServices.svc"
          binding="basicHttpBinding" bindingConfiguration="HttpBinding_IWcfMobilServices"
          contract="MobileService.IWcfMobilServices" name="HttpBinding_IWcfMobilServices"></endpoint>
    </client>
  </system.serviceModel>
</configuration>

当我调用一个服务方法时:

public static void Login()
{
    var proxy = new MobileService.WcfMobilServicesClient();
    proxy.LoginAsync("loginName", "paswword");
    proxy.LoginCompleted += (s, a) =>
        {
                //some code
        };
}

应用程序在LoginCompleted上抛出异常:

System.ServiceModel。协议例外:内容类型text/xml;服务不支持Charset =utf-8http://www.www.com/WcfMobilServices.svc。客户端和服务绑定可能不匹配。--> system.net.webeexception:远程异常服务器返回一个错误:NotFound。--> system.net.webeexception远程服务器返回一个错误:NotFound。在System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse (IAsyncResultasyncResult)System.Net.Browser.ClientHttpWebRequest灵活;> c_ DisplayClasse.b _d(对象sendState)System.Net.Browser.AsyncHelper灵活;> c_ DisplayClass1.b _0(对象sendState)——内部异常堆栈跟踪结束——atSystem.Net.Browser.AsyncHelper.BeginOnUI (SendOrPostCallback(对象状态)System.Net.Browser.ClientHttpWebRequest.EndGetResponse (IAsyncResultasyncResult)System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse (IAsyncResult内部异常堆栈跟踪结束——atSystem.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary ()在} System.ServiceModel.CommunicationException W7App.MobileService.LoginCompletedEventArgs.get_Result (){System.ServiceModel.ProtocolException}

你知道怎么了吗?

我试图将配置文件中的绑定更改为wsHttpBinding,但VS显示了一个警告:

元素'bindings'的子元素'wsHttpBinding'无效。列表'basicHttpBinding, CustomBinding'.

谢谢

WCF Service in windows phone 7

继续我们的谈话。Silverlight/Windows Phone 7 ONLY支持basicHttpBindingCustomBinding。通过创建控制台应用程序,您可以使用wsHttpBinding进行连接。所以,你的选项是:

  1. 请求将basicHttpBinding添加到端点
  2. 在Windows Phone和其他WCF服务之间创建另一个WCF服务。这样你可以连接basicHttpBinding,然后中间WCF可以使用wsHttpBinding连接到其他服务。

显然,选项2会更慢,并且会增加任何更新的复杂性和麻烦,但除非选项1是可能的,否则我认为你没有很多其他选择。