7
我已經在WCF中編寫了一個REST服務,其中我創建了一個用於更新用戶的方法(PUT)。該方法我需要通過多個身體參數如何使用webinvoke方法(Post或PUT)在wcf rest中傳遞多個body參數
[WebInvoke(Method = "PUT", UriTemplate = "users/user",BodyStyle=WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
public bool UpdateUserAccount(User user,int friendUserID)
{
//do something
return restult;
}
雖然如果只有一個參數我可以通過用戶類的XML實體。如下:
var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
myRequest.Method = "PUT";
myRequest.ContentType = "application/xml";
byte[] data = Encoding.UTF8.GetBytes(postData);
myRequest.ContentLength = data.Length;
//add the data to be posted in the request stream
var requestStream = myRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
但如何傳遞另一個參數(friendUserID)值? 任何人都可以幫助我嗎?
由於阿米特添加參數作爲節點。我做了同樣的,它的工作正常:) – 2011-03-12 09:32:21