2012-07-15 141 views
1

我創建了一個簡單的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.htmlInvalidOperationException異常而在Windows Phone的消費WCF Web服務7

所示。當我消耗這個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

難道說這個問題是本地主機?您是否在某處部署了Web服務? – 2012-07-15 12:01:45

+0

是的,我部署在IIS中。我不認爲本地主機真的會造成問題。 – 2012-07-16 07:31:20

回答

1

wsHttpBinding不支持Windows Phone。使用basicHttpBinding的,而不是...

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

+0

謝謝。我發現如果我將端點更改爲:,它的工作原理,所以」桌面「是我在IIS中的計算機名稱,沒有身份部分。任何理由?看來我必須使用桌面,不能在地址中使用localhost。 – 2012-07-16 07:30:30