WebMethod返回结果不带任何格式,直接返回纯字符串

在和某第三方系统对接时,对方要求返回结果必须是一个字符串。

我一开始用的方法是这样的

[WebMethod(EnableSession = true)]

public string TEST()      {  

    return "返回值字符串";

}

返回结果一直不成功,被xml包住:<string xmlns="http://tempuri.org/">SSOOK</string>

 

改为这样就行了:

[WebMethod(EnableSession = true)]

public void TEST()      {  

    Context.Response.Charset = "GB2312";   

     Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");       

     Context.Response.Write("返回值字符串");  

     Context.Response.End();  

   }

posted @ 2020-05-11 15:36  AdolphChen  阅读(364)  评论(0编辑  收藏  举报