I have deployed a web service by mapping to sharepoint's layout folder. It is deployed as farm solution. I am able to call web service from browser, which returns json data.

When I am trying to call the same webmethod from angular 6 service. it gives error:

Unexpected token < in JSON at position 2 at JSON.parse () at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:7458:51

Angular 6 service

baseUrl: string='http://winserv12sp13:1234/_layouts/15/GDC_Web_Service/GDC_Web_Service.asmx/GetSqlData';

getEmployees(): Observable<Salesrep[]> { 
    console.log("data from servce is"+this.http.get<Salesrep[]>(this.baseUrl));
    return this.http.get<Salesrep[]>(this.baseUrl);

web service method

    [ScriptMethod(UseHttpGet = true)]
    public void GetSqlData()
        string queryString = "SELECT *  FROM  [dbo].[TblKamDetails]";
        List<supplier> lstSupplier = new List<supplier>();         

        using (SqlConnection con = new SqlConnection(cs))
            SqlCommand cmd = new SqlCommand(queryString, con);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {[![enter image description here][1]][1]                    lstSupplier.Add(suppl);

            JavaScriptSerializer js = new JavaScriptSerializer();                


Error Image: enter image description here

Web Service Solution Structure: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.