csharp[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SomeService : System.Web.Services.WebService
{
[WebMethod(Description = "我是描述信息")]
public void MethodName(string json)
{
// 当请求方发送一个随意的JSON参数: param,此时此处的 json 并不等同于 param
// 此处 json 映射的 是 param 中的 "json"属性,若 param 中不存在属性 "json", 则报错
var stream = HttpContext.Current.Request.InputStream;
stream.Position = 0; // 读取流之前把Position设置为0
var streamReader = new StreamReader(stream, Encoding.UTF8);
// 获取真正的 param
string param = streamReader.ReadToEnd();
// todo something
JObject data = null;
try
{
data = JObject.Parse(param);
}
catch (Exception ex)
{
Console.WriteLine("入参非json字符")
}
Context.Response.Flush();
Context.Response.Write(param);
Context.Response.End();
}
}
本文作者:张京
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!