Consume PHP Soap Web Service in ASP.Net

rehansk
 
on Nov 30, 2015 02:38 AM
5816 Views

Hi

I want to call php web service in asp.net which retrun response in Json formate and I want to bind this response to gridview control.

How it is possible please guide me.

 

 

Thank you,

Download FREE API for Word, Excel and PDF in ASP.Net: Download
arjunsingh
 
on Nov 30, 2015 04:26 AM

You can do like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Web.Script.Serialization;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        WebClient wb = new WebClient();
        //Place your php url here
        string s = wb.DownloadString("http://jsonplaceholder.typicode.com/posts");
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        List<RootObject> records = serializer.Deserialize<List<RootObject>>(s);
        GridView1.DataSource = records;
        GridView1.DataBind();
    }

    //generate classes using json to c#
    public class RootObject
    {
        public int userId { get; set; }
        public int id { get; set; }
        public string title { get; set; }
        public string body { get; set; }
    }
}

 

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>
    </div>
    </form>
</body>
</html>

Try you will get the result