1

我创建了一个简单的 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 文件中的端点部分,那很好。

谁能告诉我为什么?

4

1 回答 1

1

Windows Phone 不支持 wsHttpBinding。改用 basicHttpBinding ...

http://blog.rsuter.com/?p=281

于 2012-07-15T15:05:11.267 回答