2012-09-07 183 views
2

我已經創建的,我有一個服務合同和執行合同相同的多個服務類的WCF服務。 您能否告訴我在app.config中編輯什麼以及如何在控制檯應用程序中託管此服務。 我有一個服務合同,我在wcf的三個* .cs文件中實施了這個合同。多個類實現相同的合同

謝謝。

這裏是我寫

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service name="ProductService.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8732/Design_Time_Addresses/ProductService/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address ="" binding="wsHttpBinding" contract="ProductService.IService1"> 
      <!-- 
       Upon deployment, the following identity element should be removed or replaced to reflect the 
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
       automatically. 
      --> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <!-- Metadata Endpoints --> 
     <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
     <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
     <service name="ProductService.RegistrationService"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:7777/Design_Time_Addresses/ProductService/RegistrationService/"/> 
       </baseAddresses> 
      </host> 
      <endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1"> 
       <identity> 
        <dns value ="localhost"/> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
     <service name="ProductService.ProductService"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:8888/Design_Time_Addresses/ProductService/ProductService/"/> 
       </baseAddresses> 
      </host> 
      <endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1"> 
       <identity> 
        <dns value ="localhost"/> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
     <service name="ProductService.CatogeryService"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:8080/Design_Time_Addresses/ProductService/CatogeryService/"/> 
       </baseAddresses> 
      </host> 
      <endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1"> 
       <identity> 
        <dns value ="localhost"/> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- 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> 
+3

你將不得不讓你的問題更容易比回答。首先,爲什麼不發佈您認爲與問題相關的代碼? –

+0

我已經上傳了config.hope它可以幫助你理解我的問題。 –

+0

這對你有幫助嗎? –

回答

0

我想象你的服務合同上定義了幾種服務操作的App.config?你試圖做的事情是不可能的,也不可取。

因爲一個邏輯服務正好與一個服務合同相關的,你不能爲同一合同添加多個服務。

可以爲每個服務合同添加多個服務端點,但不是基於每個操作基礎。您可能希望通過兩種或多種不同的傳輸方式來提供服務,例如HTTP和HTTPS。

可以消耗所有從單一服務的操作(你有定義的,所以剛剛擺脫過去三年的4個服務),但我不認爲這是你想要做什麼。

主辦單獨的服務端點每一個服務操作,你會需要打破你的服務合同分成多個合約。

這是更加希望的,因爲它降低了您的端點之間的耦合,使得它更容易理解到底是怎麼回事。