6

2 つのエンドポイントを持つ WCF サービスへの参照を追加しました。サービスを追加すると、次が構成ファイルに追加されます。

<client>
  <endpoint name="ABCServiceV1" address="http://staging.ABCwebservices.com/ABC/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="ABCServiceV1"
    contract="ABCService.IService"  />
  <endpoint name="ABCServiceV2" address="http://staging.ABCwebservices.com/ABC/Service.svc/20"
    binding="basicHttpBinding" bindingConfiguration="ABCServiceV2"
    contract="ABCService.IService1"  />
</client>

クライアントを作成するコードは次のとおりです。

ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV2");

ただし、ランタイム エラーが発生します。この名前に一致するエンドポイント要素がクライアント要素で見つかりました。」

私が使用した場合ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");、すべて正常に動作します。しかし、ABCServiceV2 を使用する場合、ABCService.IService1 を探す必要があるのに、Contract - ABCService.IService を探します。

正しいコントラクトのように見せるにはどうすればよいですか?

4

2 に答える 2

3

別のサービス (ABCServiceV2) への 2 つ目の参照を追加した場合、ABCServiceV2 の 2 つ目のサービス クラスが生成されると思います。2 つのクラスは別々のコントラクト (ABCService.IService と ABCService.IService1) を実装するため、エンドポイントを交換することはできません。

次のように、2 つのサービス エンドポイントを初期化できるはずです。

ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");
ABCService.Service1Client ABCClient1 = new Service1Client("ABCServiceV2");
于 2013-01-16T23:33:51.263 に答える