【问题标题】:InvalidOperationException while consuming WCF web service in Windows Phone 7在 Windows Phone 7 中使用 WCF Web 服务时出现 InvalidOperationException
【发布时间】:2012-07-15 05:33:21
【问题描述】:

我创建了一个简单的 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 中定义了自己的命名空间987654322@

当我使用这个 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 文件中的端点部分,那很好。

谁能告诉我为什么?

【问题讨论】:

  • 会不会是本地主机的问题?您是否在某处部署了 Web 服务?
  • 是的,我部署在 IIS 中。我不认为本地主机真的会导致问题。

标签: wcf windows-phone-7 invalidoperationexception


【解决方案1】:

windows phone 不支持wsHttpBinding。改用 basicHttpBinding...

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

【讨论】:

  • 谢谢。我发现如果我将端点更改为:ABC.com/ABCWcfService" address="desktop/ABCWcfService/ABCWcfService.svc" binding="basicHttpBinding" contract="ABCWcfService.IABCWcfService">,它可以工作,所以“桌面" 是我在 IIS 中的计算机名称,没有标识部分。有什么理由吗?看来我必须使用桌面,地址中不能使用localhost。
猜你喜欢
  • 2014-01-14
  • 1970-01-01
  • 2013-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
相关资源
最近更新 更多