2011-03-12 10 views
7

का उपयोग करके डब्ल्यूसीएफ आराम में एकाधिक बॉडी पैरामीटर कैसे पास करते हैं मैंने डब्ल्यूसीएफ में एक आरईएसटी सेवा लिखी है जिसमें मैंने उपयोगकर्ता को अपडेट करने के लिए एक विधि (PUT) बनाई है। इस विधि के लिए मुझे एकाधिक बॉडी पैरामीटरवेबिनवोक विधि (पोस्ट या पीयूटी)

[WebInvoke(Method = "PUT", UriTemplate = "users/user",BodyStyle=WebMessageBodyStyle.WrappedRequest)] 
[OperationContract] 
public bool UpdateUserAccount(User user,int friendUserID) 
{ 
    //do something 
    return restult; 
} 

यद्यपि मैं केवल एक पैरामीटर होने पर उपयोगकर्ता वर्ग की एक्सएमएल इकाई पास कर सकता हूं। निम्नानुसार:

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) मान कैसे पास करें? क्या कोई मेरी मदद कर सकता है?

उत्तर

11

प्राप्त करने के अलावा सभी विधि प्रकारों के लिए केवल एक पैरामीटर डेटा आइटम के रूप में भेजा जा सकता है। तो या तो

[WebInvoke(Method = "PUT", UriTemplate = "users/user/{friendUserID}",BodyStyle=WebMessageBodyStyle.WrappedRequest)] 
[OperationContract] 
public bool UpdateUserAccount(User user, int friendUserID) 
{ 
    //do something 
    return restult; 
} 

querystring या अनुरोध डेटा

<UpdateUserAccount xmlns="http://tempuri.org/"> 
    <User> 
     ... 
    </User> 
    <friendUserID>12345</friendUserID> 
</UUpdateUserAccount> 
+0

धन्यवाद अमित में नोड के रूप में पैरामीटर जोड़ने का पैरामीटर चलते हैं। मैंने वही किया और यह ठीक काम कर रहा है :) –

संबंधित मुद्दे