0

我正在.net 中创建简单的演示 rest web 服务,有两种方法可以在 web 服务中发送数据

Through Query String
Through Request Body

我编写了以下代码,并且能够通过查询字符串使用 Web 服务

    [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 ;
    }

但我必须通过请求正文而不是通过查询字符串传递 ID 值。我该怎么做?

4

1 回答 1

0

If you have to use the Form Body, then you have to add a parameter to your method :

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

Then in the method, you can access the body of the Post by :

 Dim strData As String = New IO.StreamReader(data).ReadToEnd()
于 2012-07-12T13:57:45.130 回答