2012-04-23 121 views
0

我在.NET中創建簡單的演示REST Web服務,有兩種方法可以在Web服務發送數據如何通過請求體傳遞請求值在REST Web服務

Through Query String 
Through Request Body 

我寫了下面的代碼我可以通過查詢字符串

[WebInvoke(Method = "POST", 
    ResponseFormat = WebMessageFormat.Xml, 
    BodyStyle = WebMessageBodyStyle.Wrapped, 
    UriTemplate = "xml?id={id}")] 
    string XMLData(string id); 

    public string XMLData(string id) 
    { 
      return "You request id is " + id ; 
    } 

使用Web服務,但我必須通過請求主體,而不是通過查詢字符串傳遞ID值我。如何能做到這一點?

回答

0

如果你必須使用表單主體,那麼你有一個參數添加到您的方法:

Dim strData As String = New IO.StreamReader(data).ReadToEnd() 

string XMLData(string id, data As IO.Stream); 

則在該方法中,您可以通過訪問後的身體