1

次のエンドポイントを持つサービスがあります。

<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
          name="SomeServiceDotNetEndpoint" contract="Contracts.ISomeService" />

このサービス参照を別のプロジェクトに追加すると、アプリ構成ファイルに次のクライアント エンドポイントが表示されます。

<endpoint address="http://test.example.com/Services/SomeService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISomeService"
                contract="SomeService.ISomeService" name="BasicHttpBinding_ISomeService" />

現在、この名前のエンドポイントはBasicHttpBinding_ISomeService、サービスの Web 構成ファイルで定義されていません。次のコードで新しいチャネル ファクトリを作成しようとすると:

var someServiceChannelFactory = new ChannelFactory<ISomeService>("SomeServiceDotNetEndPoint", endpoint);

失敗し、そのアドレスに一致するコントラクト/エンドポイントがないことを教えてくれます。私も使用してみまし"BasicHttpBinding_ISomeService"たが、同じエラーが発生します。

Could not find endpoint element with name 'SomeServiceDotNetEndPoint' and
contract 'SomeService.ISomeService' 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 name could be found
in the client element.

では、どこBasicHttpBinding_ISomeServiceから来たのか、元のエンドポイント名が上書きされたのはなぜですか、また、ヒットしようとしているエンドポイントをサービスに認識させるにはどうすればよいでしょうか?

4

2 に答える 2

2

サービス側でエンドポイントを定義する場合、名前を指定する必要はありません。ただし、クライアント側では、channelFactory を使用してプロキシを作成する場合に備えて、一意の名前を指定する必要があります。

要約すれば:

サービス web.config

<endpoint address="" 
          binding="basicHttpBinding" 
          contract="Contracts.ISomeService" />

クライアント app.config

<endpoint address="http://test.com/SomeService"
          binding="basicHttpBinding"
          name="someServiceEndpoint"
          contract="Contracts.ISomeService" />

コード

var someServiceChannelFactory = new ChannelFactory<ISomeService>("someServiceEndpoint", endpoint);

お役に立てれば、

ルーカス

于 2013-05-07T21:11:36.860 に答える
1

ここでの混乱のポイントは、WCF サービス構成のほとんどの "名前" 値が、サービスの外部に公開されていない実装の詳細であることです。エンドポイント名、バインディング名、サービス動作名は、サービスとクライアントにのみ表示されます。

サービス参照を作成すると、クライアントは公開されているサービス情報 (アドレス、バインディング、コントラクト) に基づいてエンドポイント名を生成し、「BasicHttpBinding_ISomeService」という名前を思いつきました。BasicHttpBinding を使用して ISomeService を公開するサービスへのすべてのサービス参照が同じ名前になることがわかります。

したがって、エンドポイント名はオーバーライドされませんでした。クライアントは、それが何であるかをまったく知りませんでした。

サービスを呼び出す最も簡単な方法は、サービス参照生成クライアントを使用することです。そのウィザードが選択したデフォルトのServiceReferece1名前空間を使用した場合:

ServiceReference1.SomeServiceClient client = new ServiceReference1.SomeServiceClient("endpointname");
于 2013-05-08T05:41:39.150 に答える