如何在angular post方法中使用.Net webservice?

时间:2018-04-20 06:32:01

标签: asp.net angular ionic-framework ionic3

如何在角度5和离子3中调用post方法。

我的角度代码为:

let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    let body= {
      records:
               this.records
             };
    this.http.post('http://localhost:13799/HealthPotliWebService.asmx/getsingleproductdetails', 
    "{body2:" + JSON.stringify(body) + "}",options)
    .map(res=>res.json())
    .subscribe(data=>{
       console.log(data);
    });
  }

这是我的网络服务类

我的班级是这样的:

    public class body2
    {
        public List<records> records { get; set; }
    }
    public class records
    {
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }
        public string Description { get; set; }
    }

网络服务代码:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string getsingleproductdetails(body2 body2)
    {
          // some code here
          return new JavaScriptSerializer().Serialize(resources);
    }

我的网络服务的返回类型是:

<string xmlns="http://tempuri.org/">
    {"error_msg":"Success","status":"0","medicinename":"CROCIN","description":"\u003cdiv style=\u0027text-align:justify;\u0027\u003e\u003cu\u003e\u003cb\u003eParacetamol\u003c/b\u003e\u003c/u\u003e-\u003cu\u003e125mg\u003c/u\u003e\u003cbr/\u003e\u003cbr/\u003e\u003c/div\u003e","lstComments":[],"rateValue":0,"potliMoney":0,"offer":null}
    </string>

0 个答案:

没有答案