あなたはAdd Service ReferenceまたはSvcUtilを使う必要はありません。インターフェイスを使用するクライアントプロキシを手動で作成できます。デフォルトのコンストラクタを使用するには、web.configにバインディングが必要です。また、エンドポイントとバインディングを渡すこともできます。
この方法の大きな利点の1つは、インターフェイスを変更してプロキシを再生成する必要があるたびに、SvcUtil.exeを操作する必要がないことです。このクラスがインターフェイスを正しく実装していないことを示す代わりに、コンパイルエラーが発生します。
SvcUtilとAdd Service Referenceは、元のサービスインターフェイスや契約にアクセスできないリモートサービスで主に使用されます。このユーティリティは単にサービスwsdlを読み込み、それを生成します。したがって、あなたのプロジェクトにすでにあるものと衝突しないことを確認するために狂った名前を付けます。
また、上記のReddogのように、サービスとデータコントラクトを別のプロジェクト/ dllに移動すると、これらを簡単に参照できるようになります。
public partial class MyServiceClient : System.ServiceModel.ClientBase<MyProject.Contracts.IMyService>, MyProject.Contracts.IMyService
{
#region IMyService Members
public void RecordSearchAnalytics(int a, int b, int c, string d, string e)
{
base.Channel.RecordSearchAnalytics(a, b, c, d, e);
}
#endregion
#region boiler plate code
public MyHServiceClient()
{
}
public MyHServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public MyHServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public MyHServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public MyHServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
#endregion
}