[英]InvalidOperationException while consuming WCF web service in Windows Phone 7
我创建了一个简单的WCF Web服务(遵循本教程: http : //blogs.msdn.com/b/ericwhite/archive/2010/05/11/getting-started-building-a-wcf-web-service.aspx ) ,因为我不想使用默认的名称空间,因此我在http://www.ilovesharepoint.com/2008/07/kill-tempuri-in-中显示的ServiceContract,DataContract,ServiceBehavior和web.config中定义了自己的名称空间wcf-services.html
使用此WCF Web服务时,在声明中不断得到InvlidOperationException:在ServiceModel客户端配置部分中找不到引用合同'ABCWcfService.IABCWcfService'的默认终结点元素。 这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该协定匹配的端点元素。
我找到原因是由于我在web.config文件中对自定义名称空间进行了端点更改。 只要我包含端点,它在我的客户端代码中就会有此异常。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ABCWcfService.ABCWcfServiceBehavior" name="ABCWcfService.SkycityWcfService">
<endpoint bindingNamespace="http://www.ABC.com/ABCWcfService" address="" binding="wsHttpBinding" contract="ABCWcfService.IABCWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ABCWcfService.ABCWcfServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
在客户端代码中,很简单:
ABCWcfServiceClient abcWcfServiceClient = new ABCWcfServiceClient();
abcWcfServiceClient.GetWhatsOnDataAsync();
abcWcfServiceClient.GetWhatsOnDataCompleted += new EventHandler<GetDataCompletedEventArgs>(ABCWcfServiceClient_GetWDataCompleted);
每当进入第一行时,我都会收到此异常。
如果我禁用了web.config文件中的终结点部分,那就很好。
谁能告诉我为什么?
Windows Phone不支持wsHttpBinding。 改用basicHttpBinding ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.