我有(如下图),我想允许对GET和POST请求的承包经营合同。我怎么能告诉WCF来接受这两种类型的请求的一个OperationContract的?
[OperationContract的,
WebInvoke(方法=POST
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate =查询)
的XElement查询(字符串QRY);
[OperationContract的,
WebInvoke(方法=GET,
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate =查询?查询= {} QRY)]
的XElement查询(字符串QRY);
解决方案
这张贴了关于MSDN论坛由卡洛斯·费圭有一个解决方案。我会去这个现在,但如果任何人有任何清洁的解决方案,让我知道。
[OperationContract的,
WebInvoke(方法=POST
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate =查询)
的XElement Query_Post(字符串QRY);
[OperationContract的,
WebInvoke(方法=GET,
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate =查询?查询= {} QRY)]
的XElement Query_Get(字符串QRY);
I have an operation contract (below) that I want to allow GET and POST requests against. How can I tell WCF to accept both types of requests for a single OperationContract?
[OperationContract,
WebInvoke(Method="POST",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "query")]
XElement Query(string qry);
[OperationContract,
WebInvoke(Method="GET",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "query?query={qry}")]
XElement Query(string qry);
解决方案
This post over on the MSDN Forums by Carlos Figueira has a solution. I'll go with this for now but if anyone else has any cleaner solutions let me know.
[OperationContract,
WebInvoke(Method="POST",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "query")]
XElement Query_Post(string qry);
[OperationContract,
WebInvoke(Method="GET",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "query?query={qry}")]
XElement Query_Get(string qry);