2

1 つのサービス コントラクトと、同じコントラクトを実装する複数のサービス クラスを持つ WCF サービスを作成しました。app.config で何を編集すればよいか、コンソール アプリでこのサービスをホストする方法を教えてください。私は 1 つのサービス コントラクトを持っており、このコントラクトを wcf の 3 つの *.cs ファイルに実装しました。

ありがとう。

ここに私が書いたApp.configがあります

<?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>
4

1 に答える 1

0

サービス契約でいくつかのサービス操作を定義したと思いますか? あなたがやろうとしていることは不可能であり、望ましいことでもありません。

論理サービスは 1 つのサービス コントラクトにのみ関連付けられるため、同じコントラクトに複数のサービスを追加することはできません。

サービス コントラクトごとに複数のサービス エンドポイントを追加できますが、操作ごとには追加できません。HTTP と HTTPS など、2 つ以上の異なるトランスポートにわたってサービスを提供するために、これを行うことができます。

1 つのサービスからすべての操作を使用できます (4 つのサービスが定義されているため、最後の 3 つを取り除くだけです)。

各サービス操作を個別のサービス エンドポイントでホストするには、サービス コントラクトを複数のコントラクトに分割する必要があります。

これは、エンドポイント間の結合を減らし、何が起こっているのかを理解しやすくするため、より望ましいものです。

于 2012-09-11T09:43:59.890 に答える