.Net4.0を使用してRESTfulWCFサービスを作成しています。次の2つのURLが必要です。
/root/document/{ids}?fields={fields}
/root/externaldocument/{ids}?fields={fields}
同じインターフェイスメンバーにマップするには:
Documents GetDocuments(string ids, string fields)
ワイルドカードをリテラルURLセグメントに入れてみました:
[OperationContract]
[WebGet(UriTemplate = "/root/*document/{ids}?fields={fields}")]
Documents GetDocuments(string ids, string fields)
ただし、これは無効であり、次の例外が発生します。
The UriTemplate '/root/*document/{ids}?fields={fields}' is not valid; the
wildcard ('*') cannot appear in a variable name or literal... Note that a
wildcard segment, either a literal or a variable, is valid only as the last
path segment in the template
ワイルドカードセグメントをテンプレートブレースでラップすると、次のようになります。
[OperationContract]
[WebGet(UriTemplate = "/root/{*document}/{ids}?fields={fields}")]
Documents GetDocuments(string ids, string fields)
次に、メソッド引数にそのような入力パラメーターがないため、例外が発生します。
Operation 'GetDocuments' in contract 'IAPIv2' has a UriTemplate that expects a
parameter named 'DOCUMENTS', but there is no input parameter with that name
on the operation.
私の回避策は、異なるメソッドを指す2つのエントリを作成し、メソッドに共通の実装を呼び出させることです。
[OperationContract]
[WebGet(UriTemplate = "/root/document/{ids}?fields={fields}")]
Documents GetDocuments(string ids, string fields)
[OperationContract]
[WebGet(UriTemplate = "/root/externaldocument/{ids}?fields={fields}")]
Documents GetExternalDocuments(string ids, string fields)
しかし、これはちょっと醜いようです。
ドキュメントを読みましたが、この点について具体的に説明することができません。WCFでワイルドカードリテラルセグメントを使用する方法はありますか?または、これはWCFでは不可能ですか?