4

IISでホストされているWCFサービスがあります。WCFクライアント(コンソールアプリケーション)もあります。以前svcutilはプロキシクラスと構成ファイルを作成し、それらをクライアントプロジェクトに追加していました。正しく構築されました。しかし、プログラムを実行しようとすると、以下の例外がスローされます

ServiceModelクライアント構成セクションでコントラクト「IService」を参照するデフォルトのエンドポイント要素が見つかりませんでした。これは、アプリケーションの構成ファイルが見つからなかったか、このコントラクトに一致するエンドポイント要素がクライアント要素で見つからなかったことが原因である可能性があります。

//クライアントプログラムコード

namespace MyFirstWCFClient
{
 class Program
 {
    static void Main(string[] args)
    {
        ServiceClient objClient = new ServiceClient();
        Console.WriteLine("Client calling the service....");

        string strName=Console.ReadLine();
        Console.WriteLine(objClient.HelloWorld("Shyju"));
        Console.Read();

    }
 }
}

私のクライアントのOutput.configファイルは

  <?xml version="1.0" encoding="utf-8"?>
   <configuration>
    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" 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="http://localhost/IISHostedserviceTest/Service.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
            contract="IService" name="WSHttpBinding_IService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
     </client>
 </system.serviceModel>
</configuration>

そして私のサービスのweb.configには以下の設定があります

   <system.serviceModel>
   <services>
    <service name="Service" behaviorConfiguration="ServiceBehavior">
    <!-- Service Endpoints -->
    <endpoint address="http://localhost/IISHostedserviceTest/Service.svc" binding="wsHttpBinding" contract="IService">
      <!-- 
          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>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- 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>

この(http://www.wcftutorial.net/WCF-IIS-Hosting.aspx)チュートリアルを使用して、WCFを試してみました。

誰かがこれを解決する方法を教えてもらえますか?

4

4 に答える 4

23

簡単な質問:クライアントアプリが呼び出された場合myclient.exe、構成はEXEと同じディレクトリにあり、呼び出されMyClient.exe.configますか?

output.configfromを取得することはできません。クライアントアプリが検索して使用するには、をクライアントコンソールプロジェクトにsvcutil追加するか(コンパイル時に名前が変更されます)、をコピー/名前変更する必要があります。それ。app.configmyclient.exe.configoutput.configmyclient.exe.config

于 2010-02-03T16:55:03.077 に答える
6

エンドポイント構成名を指定するクライアントのコンストラクターを使用する必要があります。

objClient = new ServiceClient ("WSHttpBinding_IService");

これにより、構成ファイルで指定した構成を使用するようにプロキシに指示されます。

于 2010-02-03T16:00:02.477 に答える
3

2つのWCFサービスが相互に接続している場合にも同様の問題が発生しました。

svcutil.exeを使用してoutput.config+MyService.csクラスファイルを生成し、それらをソリューションディレクトリにコピーした後、同じ問題が発生しました。

この問題に対する答えが見つかりました:「bindings」タグ全体を「ServiceModel」タグ内のメイン構成ファイルにコピーし、参照されるエンドポイントをメイン構成ファイルの既存のエンドポイントの隣にコピーする必要があります-これで例外の問題が解決しました

于 2011-06-29T15:40:56.410 に答える
2

もう1つの方法は、IISでホストされているサービスにサービス参照を追加することです。Visual Studioはバックグラウンドでsvcutilを自動的に実行し、構成作業を行います。つまり、app.configが作成されます。

手動で行うのは問題ありませんが、正しく機能することを確認するために、サービスリファレンスを追加して少なくとも1回は実行することをお勧めします。

于 2010-02-03T17:14:38.930 に答える