如果有人在寻找不同的解决方案,
[OperationContract] [WebInvoke(Method="*")] public <> DoWork() { var method = WebOperationContext.Current.IncomingRequest.Method; if (method == "POST") return DoPost(); else if (method == "GET") return DoGet(); throw new ArgumentException("Method is not supported."); }
这篇由Carlos Figueira在MSDN论坛上发布的帖子有一个解决方案.我现在就说这个,但如果有人有任何更清洁的解决方案让我知道.
[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);