2

WCF 構成のセットアップに関する基本的なガイダンスが必要です。これは、WCF に関する私の最初の本格的な取り組みです (そして、stackoverflow に関する最初の投稿です)。

Web プロジェクトで参照している WCF クラス ライブラリ (APILibrary) があります。wcf ライブラリには、現在 IAuthService と ITradeService の 2 つのサービスがあります。

これらに沿って、3 つの質問があります。

1)私の問題 (およびこの投稿の元の理由) は、アプリケーションをコンパイルすると、Web アプリで TradeServiceCient を呼び出すことができますが、AuthServiceClient を呼び出すことができないことです。後者は、インテリセンスには表示されません。それらが同じポートを共有している(そして含まれているエンドポイントは1つだけである)という事実に関係していると感じていますが、明らかに不明です.

2) 開発およびテスト中に、2 つのサービス エンドポイントを同時に公開しようとしています (おそらくさらにいくつか)。ステージングとホスティングに移行すると、各エンドポイントには独自のアドレスが割り当てられます。それまでは、どうすればいいですか (これは上記の質問に関連していると感じています)。

3)多くの投稿で、「クライアント」と「サーバー」の「system.serviceModel」コードの例があることに気づきました。これらの一意のファイルまたはタグは、WCF ライブラリにある App.config ファイルにありますか? それぞれ何をしているの?現在、私はサーバー側だけを持っていると思いますか?

現在、App.config ファイル (WCF ライブラリ内) にあるものは次のとおりです。

<?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>
    <client />
    <services>
      <service behaviorConfiguration="ApiLibrary.ApiBehavior" name="SpoonSys.Api.Trade.TradeService">
        <endpoint address="" binding="wsHttpBinding" contract="SpoonSys.Api.Trade.ITradeService">
          <identity>
            <dns value="localhost:8731" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/ApiLibrary/Trade/" />
          </baseAddresses>
        </host>
      </service>

      <service behaviorConfiguration="ApiLibrary.ApiBehavior" name="SpoonSys.Api.Authentication.AuthService">
        <endpoint address="" binding="wsHttpBinding" contract="SpoonSys.Api.Authentication.IAuthService">
          <identity>
            <dns value="localhost:8731" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/ApiLibrary/Authentication/" />
          </baseAddresses>
        </host>
      </service>  
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ApiLibrary.ApiBehavior">
          <!-- 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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

私の構成は ASP.NET / Framework 3.5 / VS 2008 / C# です

4

2 に答える 2

4

はい、あなたの場合、サーバー側のみを扱っているので、実際には構成はまったく問題ないように見えます。

構成で変更する唯一のことは、「baseAddress」と実際のサービスアドレスの分割です。現在、ベースアドレスで完全なアドレス全体を定義しています。これは、ベースアドレスの目的に反しています。私はそれを次のように分割します:

 <service name="SpoonSys.Api.Services"
          behaviorConfiguration="ApiLibrary.ApiBehavior" >
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/Design_Time_Addresses/ApiLibrary/" />
      </baseAddresses>
    </host>
    <endpoint 
       address="Trade" 
       binding="wsHttpBinding" 
       contract="SpoonSys.Api.Trade.ITradeService">
      <identity>
        <dns value="localhost:8731" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

そうすれば、基本的に 2 つのエンドポイントを 1 つにまとめることができます。ベース アドレスはそれを定義し、他のすべてのアドレスの共通ベースを定義します。一方、エンドポイントは完全なアドレスの詳細を定義します。

 <service name="SpoonSys.Api.Services"
          behaviorConfiguration="ApiLibrary.ApiBehavior" >
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/Design_Time_Addresses/ApiLibrary/" />
      </baseAddresses>
    </host>
    <endpoint 
       address="Trade" 
       binding="wsHttpBinding" 
       contract="SpoonSys.Api.Trade.ITradeService">
      <identity>
        <dns value="localhost:8731" />
      </identity>
    </endpoint>
    <endpoint 
       address="Authentication" 
       binding="wsHttpBinding" 
       contract="SpoonSys.Api.Authentication.IAuthService">
      <identity>
        <dns value="localhost:8731" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

これは、これらのサービス コントラクトの両方を実装する単一のサービス クラス「SpoonSys.Api.Services」がある場合に機能します。これはまったく問題なく、場合によっては非常に便利です。

それぞれ1つのインターフェースを実装する2つの別個のサービスクラスが必要な場合、このように構成を折りたたむことはできません-元の投稿で2つの別個のサービスクラスの完全な構成を使用する必要があります(私には問題ないようでした)。

もう 1 つの質問は、IntelliSense で 1 つのエンドポイントしか表示されない理由です。両方のエンドポイントに対してクライアント プロキシを作成しましたか? これは 2 つの別個の契約であるため、2 つの別個のクライアント プロキシが必要になります。クライアント エンドポイントはどのように作成しましたか? クライアント構成も投稿できますか?

マルク

于 2009-07-22T20:38:19.677 に答える
0

私はあなたの提案に従ってベースアドレスを短くしてみました。その後、一方のサービスが開始され、もう一方のサービスは開始されないというエラーが発生しました。メタデータエンドポイントはすでに使用されていると言われていました。次に、すべてのクラスファイルについて、名前空間をSpoonSys.ApiLibrary.AuthenticationおよびSpoonSys.ApiLibrary.TradeからSpoonSys.ApiLibaryのみに変更してみました。それでも-同じエラー。元のサーバー構成に戻すと、コンパイルされました。それでも、インテリセンスは一方のサービスのみを取得し、もう一方のサービスは取得しません。

クライアント構成ファイルの意味がわかりません。クライアントアプリプロジェクトでWCFに関して特に何もしていません(Webサービス参照としてWCFクラスライブラリをインポートする場合を除く)。多分これは私が間違っているところですか?ここでもっと教えてもらえますか?

各エンドポイントのWCFエディターでClient.dllに気づき、以下に投稿しました。

ENDPOINT:localhost:8731 / Design_Time_Addresses / Authentication / mex

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ITradeService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="localhost:8731/Design_Time_Addresses/Trade/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITradeService"
                contract="ITradeService" name="WSHttpBinding_ITradeService">
                <identity>
                    <dns value="localhost:8731" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

エンドポイント:http:// localhost:8731 / Design_Time_Addresses / Trade / mex

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IAuthService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="localhost:8731/Design_Time_Addresses/Authentication/"
                binding="wsHttp binding" bindingConfiguration="WSHttpBinding_IAuthService"
                contract="IAuthService" name="WSHttpBinding_IAuthService">
                <identity>
                    <dns value="localhost:8731" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

そして最後に、これが私のAPP.CONFIGAGAINです。

<?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 behaviorConfiguration="ApiLibrary.ApiBehavior"
        name="SpoonSys.ApiLibrary.Trade.TradeService">
        <endpoint address="" binding="wsHttpBinding" contract="SpoonSys.Api.Trade.ITradeService">
          <identity>
            <dns value="localhost:8731" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/Trade/" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="ApiLibrary.ApiBehavior"
        name="SpoonSys.Api.Authentication.AuthService">
        <endpoint address="" binding="wsHttpBinding" contract="SpoonSys.ApiLibrary.Authentication.IAuthService">
          <identity>
            <dns value="localhost:8731" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="localhost:8731/Design_Time_Addresses/Authentication/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ApiLibrary.ApiBehavior">
          <!-- 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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

PS-応答を送信しようとすると、「新規ユーザーは最大1つのハイパーリンクしか投稿できない」というメッセージが表示されるので、投稿内のすべての「http://」参照を削除しました。コードエラーではありません。

于 2009-07-23T20:37:26.380 に答える