using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web .Script .Serialization;
namespace ReturnJSONandXML
{
/// <summary>
/// Summary description for service
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class service : System.Web.Services.WebService
{
[WebMethod]
public string GetcompaniesJSON()
{
companies[] COMP = new companies[]{
new companies ()
{
companytid ="C123",
companynm ="TCS"
},
new companies ()
{
companytid ="C1234",
companynm ="wipro"
}
};
return new JavaScriptSerializer().Serialize(COMP);
}
}
}
我正在使用此代码。
请告诉我如何制作纯发布方法Web服务以及如何在客户端调用它?
这段代码提供了这种类型的输出
<string xmlns="http://tempuri.org/">
[{"companytid":"C123","companynm":"TCS"},{"companytid":"C1234","companynm":"wipro"}]
</string>