Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

WCF Webサービスではメソッドのオーバーロードはできない

WCF Webサービスでは、メソッドのオーバーロードはできません。
具体的には、以下のようなシグネチャはビルドは正常終了しますが、クライアント側でプロキシクラスを自動生成する際にエラーになります。

シグネチャ

[ServiceContract]
public interface IService1
{
    [OperationContract]
    void Hoge(int value);

    [OperationContract]
    void Hoge(string value);
}

これはWSDLの仕様のようです。
Web Services Description Language (WSDL) Version 1.2
This document describes the Web Services Description Language (WSDL) Version 1.2, an XML language for describing Web services. This specification defines the core language which can be used to describe Web services based on an abstract model of what the service offers. ...

[CLOSED] Issue (issue-operation-overloading):
Should operation overloading be disallowed?
Source: Joyce Yang
WSDL 1.1 allows overloaded operations- operations with the same name but different messages. If they are to be disallowed then we must require the operation name to be unique within a portType.
Resolution:
Do not allow operation overloading. See minutes for telecon on June 27, 2002 and follow-on email discussion.

エラー内容


同じ名前の 2 つの操作を同一のコントラクトに含めることはできません。型 [名前空間].[クラス名] のメソッド [メソッド名] および [メソッド名] はこのルールに違反しています。いずれかの操作の名前を変更するには、メソッド名を変更するか、OperationContractAttribute の Name プロパティを使用します。

解決方法

メソッド名を変更するか、OperationContractAttribute の Name プロパティを使用します。