2

how to access the web service which has been developed in PHP in C#.

Here is the link: http://xxx.in/WS/getCities.php?wsdl

I just want to call the getCities() method from that.

I written code in C# like this:

Chanllange.LocationInformationService ls = new  Chanllange.LocationInformationService();
t1.Text= ls.getCities();

I have got the output in json format, how to show the value in c#.

Please let me know if you need more information.

BhushanK
  • 1,205
  • 6
  • 23
  • 39
Thirisangu Ramanathan
  • 614
  • 1
  • 11
  • 20
  • What do you mean by "how to show the value in c#"? – RePierre Jul 11 '12 at 07:12
  • Well, by using the getCities() method, i got the result in JSON format. Now i want to display the JSON value in Message box. how to do that in C#? – Thirisangu Ramanathan Jul 11 '12 at 07:30
  • You're displaying it `t1.Text = ls.getCities();`. Or there is a problem when invoking the method? – RePierre Jul 11 '12 at 08:04
  • well, the methods displays the JSON value Something "O:8:"stdClass":2:{s:8:"Response";O:8:"stdClass":5:{s:12:"responseType";s:11:"Information";s:9:"IsSuccess";b:1;s:12:"ResponseCode";i:400;s:15:"ResponseMessage";s:7:"Sucess.";s:10:"Suggestion";s:6:"Sucess";}s:6:"Cities";O:8:"stdClass":1:{s:4:"City";a:2103:{i:0;O:8:"stdClass":2:{s:6:"CityID";i:1051;s:8:"CityName";s:7:"Aachara";}i:1;O:8:"stdClass":2:{s:6:"CityID";i:1166;s:8:"CityName";s:6:"Aanjar";}i:2;O:8:"stdClass":2:{s:6:"CityID";i:73401;s:8:"CityName";s:6:"Aaspur";}i:3;O:8:"stdClass":2:" , How to convert this value into readable form – Thirisangu Ramanathan Jul 11 '12 at 08:41

1 Answers1

0

See Parse JSON in C# if this helps. You need to create a class for getting the data in json format. From there you can use the JSON Classes and move forward.

For Example

Have a class public class Person { private string _FirstName; private string _LastName; private string _MiddleName;

    public string FirstName
    {
        get { return this._FirstName; }
        set { this._FirstName= value; }
    }

    public string LastName
    {
        get { return this._LastName; }
        set { this._LastName= value; }
    }

    public string MiddleName
    {
        get { return this._MiddleName; }
        set { this._MiddleName= value; }
    }

}

And have a method to populate this class

public void ReadJSON(string jsonInput)

{

  JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();

  Person singlePerson  = jsonSerializer.Deserialize<Person>(jsonInput)

}
Community
  • 1
  • 1
Peru
  • 2,871
  • 5
  • 37
  • 66