2012-09-07 147 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个服务),但我不认为这是你想要做什么。

主办单独的服务端点每一个服务操作,你会需要打破你的服务合同分成多个合约。

这是更加希望的,因为它降低了您的端点之间的耦合,使得它更容易理解到底是怎么回事。