我创建了一个简单的WCF Web服务(遵循本教程:http://blogs.msdn.com/b/ericwhite/archive/2010/05/11/getting-started-building-a-wcf-web-service.aspx),因为我不想使用默认命名空间,所以我在ServiceContract,DataContract,ServiceBehavior和web.config中定义了我自己的命名空间在http://www.ilovesharepoint.com/2008/07/kill-tempuri-in-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文件中禁用了端点部分,那很好。
谁能告诉我为什么?
答案 0 :(得分:1)
Windows Phone不支持wsHttpBinding。请改用basicHttpBinding ......