C# WSDL web服务 webservice 返回纯json 并让Web服务支持HTTP请求

C# WSDL web服务 webservice 返回纯json 并让Web服务支持HTTP请求

改变数据的返回方式,
用 Context.Response.Write代替return 语句
,修改方法如下即可返回正确的Json格式数据。

[WebMethod]  
    public void GetTest(String code)  
    {           
        String json=这里是转换的json结果
        Context.Response.Write(json);  
        Context.Response.End();  ##这里不用return 来实现返回,即可以跳过wsdl默认的返回方式。
    }

Web.Config
##向<system.web>中添加

<webServices>
        <protocols>
          <add name="HttpPost"/>
          <add name="HttpGet"/>
        </protocols>
</webServices>
发布了48 篇原创文章 · 获赞 3 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/chscomfaner/article/details/103729828