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>