启用单操作多个HTTP方法? [英] Enable multiple HTTP Methods on a single operation?

查看:140
本文介绍了启用单操作多个HTTP方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有(如下图),我想允许对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);
 

解决方案

这张贴了关于<一个href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ad5bb2f0-058c-47ae-bcf3-8f5c4727a70e/">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);

这篇关于启用单操作多个HTTP方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆