【发布时间】:2013-05-09 17:16:26
【问题描述】:
我在连接 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 中的应用程序在 a.Result 上抛出异常:
System.ServiceModel.ProtocolException:内容类型文本/xml; charset=utf-8 不受服务支持 http://www.www.com/WcfMobilServices.svc。客户和服务 绑定可能不匹配。 ---> System.Net.WebException:远程 服务器返回错误:未找到。 ---> System.Net.WebException: 远程服务器返回错误:未找到。在 System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.ClientHttpWebRequest.c_DisplayClasse.b_d(Object 发送状态)在 System.Net.Browser.AsyncHelper.c_DisplayClass1.b_0(Object sendState) --- 内部异常堆栈跟踪结束 --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback 开始方法,对象状态)在 System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult 结果)---内部异常堆栈跟踪结束---在 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在 W7App.MobileService.LoginCompletedEventArgs.get_Result()} System.ServiceModel.CommunicationException {System.ServiceModel.ProtocolException}
知道有什么问题吗?
我尝试将配置文件中的 Binding 更改为 wsHttpBinding,但 VS 显示警告:
元素“绑定”具有无效的子元素“wsHttpBinding”。列表 预期的可能元素数:'basicHttpBinding, CustomBinding'。
谢谢
【问题讨论】:
-
如果你继续警告会发生什么?这可能是重复的:stackoverflow.com/questions/8250251/…
-
如果我忽略配置中的警告,应用程序会在创建 wcf 类的实例期间向我抛出错误:服务参考配置中无法识别元素“wsHttpBinding”。请注意,Silverlight 中只有一部分 Windows Communication Foundation 配置功能可用。
-
Silverlight / WP7 只支持 Basic HTTP 很遗憾。您知道您尝试连接的端点是否支持基本 HTTP 绑定?可能没有?
-
真的不知道。我只描述了服务方法和网址
-
@Ex_animo - 尝试创建一个简单的控制台应用程序并连接到端点。这将允许 wsHttpBinding 等。这行得通吗?如果是这样,看起来端点不支持 basicHttpBinding,这意味着您可能还有很多工作要做!
标签: c# wcf windows-phone-7