0

私は WCF を初めて使用し、最初のサービス (単純な使用状況レポート サービス) を作成しようとしています。例とチュートリアルを見て、サービスを作成しました。コア コードを実行してレポートを送信できる簡単なテスト プログラムがあります。現在、デバッガーでローカルにホストされて実行していますが、この単純な exe プログラムを実行すると、サービスがホストされ、レポートが送信され、サービスが想定どおりにログ ファイルが作成されます...すべて問題ありません。

現在、私の実際のプログラムは、API (Autodesk Revit) で実行される別の商用プログラムへのアドインです。Revit API 内でまったく同じコードを実行すると、エンドポイントが定義されていないというエラーが表示されます。これは、明らかにエンドポイントが定義されていないメインの Revit.exe.config を探しているためだと思います。作成した dll の .config ファイル (MyLibrary.dll.config) と、コードの実行ディレクトリに、エンドポイントを適切に定義していますが、認識されていないようです。

だから私の質問は、この構成ファイルから接続設定をロードするにはどうすればよいですか? または、これを行うべき別の方法はありますか?どういうわけかコードで設定することはできますが、接続する方法がわかりません...

問題があるかどうかはわかりませんが、スタンドアロン プログラムで動作している構成は次のとおりです。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
      <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_IReportingService" />
        </basicHttpBinding>
      </bindings>
      <client>
        <endpoint address="http://localhost:8733/Design_Time_Addresses/SPECtrumReportingService/Service1/"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReportingService"
            contract="ReportService.IReportingService" name="BasicHttpBinding_IReportingService" />
      </client>
    </system.serviceModel>
</configuration>

エンドポイント例外をスローしている私のコンストラクターは単純です:

_reporter = new ReportingServiceClient();

スローされる例外は次のとおりです。

Could not find default endpoint element that references contract 'ReportService.IReportingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at RDES.Revit.Sumex.CommonUse.ReportService.ReportingServiceClient..ctor() in c:\RD\Projects\13-004 SPECtrum\Code\SPECtrumBase\Service References\ReportService\Reference.cs:line 241
   at RDES.Revit.Sumex.CommonUse.ImportVM..ctor() in c:\RD\Projects\13-004 SPECtrum\Code\SPECtrumBase\ImportVM.cs:line 41

どんな助けでも大歓迎です...

4

3 に答える 3

0

可能な答えにつながるこの投稿を見つけました。コンストラクターを次のように更新しました。

_reporter = new ReportingServiceClient(new BasicHttpBinding(), new EndpointAddress("http://localhost:8733/Design_Time_Addresses/SPECtrumReportingService/Service1/"));

バインディングはデフォルトのままにしましたが、必要に応じて他のプロパティを設定できるようです。スタンドアロン プログラムで動作する構成ファイルからエンドポイント アドレスを取り出し、それを使用して構築しました。

これは、少なくとも予備テストでは、Revit 内で期待どおりに機能しているようです。これが問題を引き起こすかどうか、またはこの状況を処理するためのより良い方法があるかどうかについて、誰かコメントできますか?

于 2014-08-22T05:35:44.193 に答える