0
我所有的GET端點都像冠軍一樣工作,但我試圖實現webinvoke方法=「POST」。來自WCF網絡調用的錯誤請求
我認爲我的格式有問題,但我不能告訴它是什麼,有人可以幫忙嗎?
[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? – 2011-12-28 13:54:10
另外,如何定義FlowRate類? – carlosfigueira 2011-12-28 17:36:20
url = localhost:4369/FlowRate/Add?apikey = 32q13e4-c78a-ce9d-e011-15eacd8e8958「; {[DataContract] public class FlowRate {[DataMember] public string wellname {get; set;}}} – Matt 2011-12-28 20:02:13