【发布时间】:2011-12-28 13:40:44
【问题描述】:
我所有的 GET 端点都像冠军一样工作,但我正在尝试实现 webinvoke method="POST"。
我认为我的格式有问题,但我不知道是什么问题,有人可以帮忙吗?
[ServiceContract]
interface iFlowRate
{
[OperationContract]
[WebInvoke(Method="POST",UriTemplate = "Add?apikey={apikey}",RequestFormat= WebMessageFormat.Xml)]
string AddFlowRate(string apikey,FlowRate flowrate);
}
当我调试它时,它甚至没有进入这个方法。 我是这样调用服务的。
string postData = "<FlowRate ><wellname>wellname</wellname></FlowRate>";
//Setup the http request.
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentLength = postData.Length;
request.ContentType = "application/xml";
request.KeepAlive = true;
StreamWriter streamwriter = new
StreamWriter(request.GetRequestStream());
streamwriter.Write(postData);
streamwriter.Close();
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Read the response
StreamReader responsereader = new StreamReader(response.GetResponseStream());
string strResponseData = responsereader.ReadToEnd();
有什么想法吗?顺便说一句,使用 WCF 4.0,非常感谢任何帮助。
【问题讨论】:
-
您尝试 POST 的 URL 是什么?
-
另外,FlowRate 类是如何定义的?
-
url = localhost:4369/FlowRate/Add?apikey=32q13e4-c78a-ce9d-e011-15eacd8e8958"; { [DataContract] public class FlowRate { [DataMember] public string wellname { get; set; } } }