2013-08-24 212 views
0

我有一個IIS託管的WCF Web服務。它從兩個消費者開始。WCF端點。多個客戶端

1)在同一解決方案中測試WCF契約的IDE中的WinForm測試工具。

2)使用發佈版本的Asp.Net Web應用程序。

所有的開箱即可使用。

然後沿着第三名消費者,一個Android應用程序。爲了正確使用這個消息,必須用JSON WebGets和Webinvokes修飾WCF契約,並修改WCF Web.config以適應。

現在原來的兩位消費者不再工作。所以我需要改變Web.config和/或App.configs來獲得配置,其中所有三個工作。

首先關注IDE。我有WCF服務Web.Config的以下服務模型部分。

<system.serviceModel> 
    <client> 
    <endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding" 
       contract="CouponParkingWCF.ICouponService" name="Json" 
       kind="" endpointConfiguration=""> 
     <identity> 
     <certificateReference storeName="My" storeLocation="LocalMachine" 
           x509FindType="FindBySubjectDistinguishedName" /> 
     </identity> 
    </endpoint> 
    <endpoint address="http://localhost:8707/CouponParking.svc" 
       binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService" 
       name="BasicHttpBinding_ICouponService" /> 
    </client> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="basicHttp" /> 
    </basicHttpBinding> 
    <webHttpBinding> 
     <binding name="JsonBinding" /> 
    </webHttpBinding> 
    </bindings> 
    <services> 
    <service name="CouponParkingWCF.CouponService"> 
     <endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding" 
       bindingConfiguration="" name="jsonEndPoint" 
       contract="CouponParkingWCF.ICouponService" /> 
    </service> 
    </services> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name="JsonBehavior"> 
     <webHttp /> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
    <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
          multipleSiteBindingsEnabled="false" /> 
</system.serviceModel> 

的WinForm的測試工具的App.config有:

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="BasicHttp" /> 
    </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint address="http://localhost:8707/CouponParking.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttp" 
       contract="CouponParking.ICouponService" 
       name="BasicHttpBinding_ICouponService" /> 
    </client> 
</system.serviceModel> 

我不是在配置終結點經驗豐富,上面已經基於實例和猜測。

當我運行測試工具WCF客戶端實例,但合同上的呼叫失敗:

There was no endpoint listening at http://localhost:8707/CouponParking.svc 
that could accept the message. This is often caused by an incorrect address 
or SOAP action. See InnerException, if present, for more details." 

內部異常是:

{"The remote server returned an error: (404) Not Found."} 
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."} 
Data: {System.Collections.ListDictionaryInternal} 
HelpLink: null 
HResult: -2146233079 
InnerException: null 
Message: "The remote server returned an error: (404) Not Found." 
Source: "System" 
StackTrace: " at System.Net.HttpWebRequest.GetResponse()\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)" 
TargetSite: {System.Net.WebResponse GetResponse()} 

我將不勝感激一些指導我出錯了。

感謝

+0

您是否試圖在相同的端點上向不同的客戶端(具有不同的需求 - 即綁定)公開相同的服務?如果是這樣,你不能那樣做。您需要爲不同的服務實現公開不同的端點。 – Tim

+0

此外,你可以發佈配置文件,因爲它們*在添加第三個客戶端之前?它可能有助於瞭解它在工作時的狀態,以及它現在的狀態(不工作時)。 – Tim

+0

每個服務器端端點具有**一個定義的綁定**你**不能擁有一個支持你的第一個和第二個客戶端的'basicHttpBinding'(SOAP)的單個端點,同時也支持Android客戶端的'webHttpBinding'(REST)。您需要爲此使用**兩個單獨的端點**。 –

回答

4

一目瞭然,看來你已經混了服務端點客戶端點服務的配置文件。除非該服務本身正在調用其他服務,否則沒有理由讓客戶端出現在服務的配置文件中。

你的WinForm的配置文件中被定義客戶端basicHttpBinding,但你不公開服務端點BasicHttpBinding,這是最有可能爲你得到錯誤的原因。

我會嘗試刪除您的服務中的配置文件的客戶端點,並把它們添加到<services>部分,像這樣:

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="basicHttp" /> 
    </basicHttpBinding> 
    <webHttpBinding> 
     <binding name="JsonBinding" /> 
    </webHttpBinding> 
    </bindings> 
    <services> 
    <service name="CouponParkingWCF.CouponService"> 
     <endpoint address="SOAP" 
       binding="basicHttpBinding" 
       contract="CouponParkingWCF.ICouponService" 
       name="BasicHttpBinding_ICouponService" /> 
     <endpoint address="JSON" 
       binding="webHttpBinding" bindingConfiguration="JsonBinding" 
       contract="CouponParkingWCF.ICouponService" name="Json" 
       kind="" endpointConfiguration=""> 
     <identity> 
      <certificateReference storeName="My" storeLocation="LocalMachine" 
           x509FindType="FindBySubjectDistinguishedName" /> 
     </identity> 
     </endpoint> 
    </service> 
    </services> 

記住ABC的WCF的:一個 =地址, =綁定和C =合同 - 這三項定義了一項服務。

由於您添加了需要不同綁定的客戶端,所以您的測試工具或ASP.NET應用程序需要使用該綁定公開第二個端點。

EDITED

由於@marc_s指出的那樣,你需要兩個不同的相對地址。我更新了配置文件以反映這一點。

我已經沒有了機會使用多個端點自己,但我相信會使用他們這種方式,與基址由* .svc文件的位置被規定:

http://localhost:8707/CouponParking.svc/SOAP 
http://localhost:8707/CouponParking.svc/JSON 

第一個是BasicHttpBinding,第二個是WebHttpBinding

+0

您必須爲您定義的這兩個端點提供兩個不同的地址。他們的「基地」地址由IIS虛擬目錄和'* .svc'文件的位置定義 - 現在你需要兩個不同的相對地址來區分這兩個端點...... –

+1

@marc_s - 謝謝。我已經更新了我的回答,以反映我對你所說的內容的理解。如果仍然有誤,請告訴我。 – Tim

+0

感謝Tim,你和marc_s不僅提供瞭解決方案,而且提供了一個明確的解釋。您的答案在marc_s之前,所以我已標記爲答案。 –

3

你基本上只需要兩個獨立的端點既提供basicHttpBinding(SOAP綁定)和webHttpBinding您的Android客戶端(REST綁定)。

「基地」你的服務的地址由IIS虛擬目錄的定義,其中*.svc文件生命(http://localhost:8707/CouponParking.svc) - 所以這兩種服務將到達這個「基地」地址加任何相對地址定義

所以,你需要配置該是這樣的:

<services> 
    <service name="CouponParkingWCF.CouponService"> 
     <!-- define the basicHttp (SOAP) endpoint at the base address --> 
     <endpoint name="SoapEndpoint" 
      address="" 
      binding="basicHttpBinding" 
      contract="CouponParkingWCF.ICouponService" /> 
     <!-- define the REST endpoint at (base)+"/rest" --> 
     <endpoint name="RestEndpoint" 
      address="rest" 
      behaviorConfiguration="JsonBehavior" 
      binding="webHttpBinding" 
      contract="CouponParkingWCF.ICouponService" /> 
    </service> 
</services> 

採用這種設置,你應該能夠在

http://yourServer:8707/CouponParking.svc 
調用使用 basicHttpBinding(SOAP)服務

,你應該能夠在

http://yourServer:8707/CouponParking.svc/rest 

兩個服務器端的端點將使用相同的服務代碼來處理訪問基於REST的,啓用JSON-終點 - 它只是端點(和協議的端點理解)不同

+0

你和蒂姆都是對的。我已經標記了蒂姆的回答,因爲他是第一個。我不僅感謝解決方案,而且感謝解釋。 –