C# windows phone 7中的WCF服务
我在连接WCF服务和Windows Phone时遇到问题。我有一个没有源代码的服务(只在网上发布),我需要在WindowsPhone7应用程序中使用它 我在项目中添加了服务引用,VS生成的me文件ServiceReferences.ClientConfig:C# windows phone 7中的WCF服务,c#,wcf,windows-phone-7,C#,Wcf,Windows Phone 7,我在连接WCF服务和Windows Phone时遇到问题。我有一个没有源代码的服务(只在网上发布),我需要在WindowsPhone7应用程序中使用它 我在项目中添加了服务引用,VS生成的me文件ServiceReferences.ClientConfig: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings>
<?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>
LoginCompleted中的应用程序对a抛出异常。结果:
System.ServiceModel.ProtocolException:内容类型text/xml;
服务不支持字符集=utf-8
. 客户与服务
绑定可能不匹配。-->System.Net.WebException:远程
服务器返回错误:未找到。-->System.Net.WebException:异常
远程服务器返回错误:NotFound。在
System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult
异步结果)在
System.Net.Browser.ClientHttpWebRequest.c_DisplayClasse.b_d(对象
发送状态)在
System.Net.Browser.AsyncHelper.c_DisplayClass1.b_0(对象
sendState)---内部异常堆栈跟踪的结束----at
System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback
beginMethod,对象状态)位于
System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult
异步结果)在
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTresponse(IAsyncResult
结果)--内部异常堆栈跟踪的结束---at
System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfEssential()
在
W7App.MobileService.LoginCompletedEventArgs.get_Result()}System.ServiceModel.CommunicationException
{System.ServiceModel.ProtocolException}
知道怎么了吗
我试图将配置文件中的绑定更改为wsHttpBinding,但VS向我显示了一条警告:
元素“bindings”具有无效的子元素“wsHttpBinding”。列表
预期的可能元素的数目:“basicHttpBinding,CustomBinding”
谢谢继续我们的谈话。Silverlight/Windows Phone 7仅支持
BasichtpBinding
和CustomBinding
。通过创建控制台应用程序,您可以使用wsHttpBinding
进行连接。因此,您的选择是:
basicHttpBinding
添加到端点basicHttpBinding
,然后中间WCF可以使用wsHttpBinding
连接到其他服务显然,选项2的速度会较慢,并且会增加更新的复杂性和麻烦,但除非选项1可行,否则我认为您没有其他选择。如果继续警告,会发生什么?这可能是重复的:若我忽略配置中的警告,那个么在创建wcf类实例时,应用程序会抛出一个错误:服务引用配置中无法识别的元素“wsHttpBinding”。注意,只有Silverlight中的Windows通信基础配置功能的子集可用。Silverlight /WP7不幸地只支持基本HTTP。您知道您尝试连接的端点是否支持基本HTTP绑定吗?可能不是吗?真的不知道。我只描述了一些服务方法和web服务address@Ex_animo-尝试创建一个简单的控制台应用程序并连接到端点。这将允许wsHttpBinding等。这样做有效吗?如果是这样的话,看起来端点不支持basicHttpBinding,这意味着您可能还有很多工作要做!
public static void Login()
{
var proxy = new MobileService.WcfMobilServicesClient();
proxy.LoginAsync("loginName", "paswword");
proxy.LoginCompleted += (s, a) =>
{
//some code
};
}