# How to consume JSON RO Web services?

**URL:** https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354
**Category:** Data Abstract
**Created:** [June 10, 2015, 4:14am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354 "2015-06-10T04:14:46Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![wilson](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@wilson](https://talk.remobjects.com/u/wilson)
#### Post date: [June 10, 2015, 4:14am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/1 "2015-06-10T04:14:46Z")

</div>

Hi,

refer to the document [http://wiki.remobjects.com/wiki/WIP:How\_to\_consume\_RemObjects\_SOAP\_services\_with\_third\_party\_clients](http://wiki.remobjects.com/wiki/WIP:How_to_consume_RemObjects_SOAP_services_with_third_party_clients)

i manage to consume the soap services, would like to check how about the JSON ? i have add in the JSON message type in to server channel. Below is my test in client program:

protected void btnSoap\_Click(object sender, EventArgs e)  
{  
System.ServiceModel.Channels.Binding b = (System.ServiceModel.BasicHttpBinding)Activator.CreateInstance(typeof(System.ServiceModel.BasicHttpBinding));  
System.ServiceModel.EndpointAddress eAddress = new System.ServiceModel.EndpointAddress(“[http://localhost:8099/soap](http://localhost:8099/soap)”);

```
        soapServices.ROServer1ServiceClient iTest = new soapServices.ROServer1ServiceClient(b, eAddress);

        var msgHeader = new soapServices.ROClientIDHeader();
        msgHeader.ID = String.Concat("{", Guid.NewGuid().ToString(), "}");

        var result = iTest.GetServerTime(ref msgHeader);
        txtResultSOAP.Text = result.ToString();
    }

```

Thanks.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [June 10, 2015, 8:51am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/2 "2015-06-10T08:51:18Z")

</div>

You’d need to compose a requiest JSON string, send it to the server at http://[servername]:[serverport]/json (using .NET WebClient or similar class), then get back a response JSON string and parse it.

[http://json2csharp.com/](http://json2csharp.com/) can help you to generate .NET classes that match the provided JSON string.  
Requested JSON string formats can be viewed using Fiddler: create RO SDK client and server and inspect the traffic between them using this awesome tool.

---

<div class="post-metadata">

### Author: ![wilson](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@wilson](https://talk.remobjects.com/u/wilson)
#### Post date: [June 11, 2015, 7:52am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/3 "2015-06-11T07:52:16Z")

</div>

Hi, we use the sample server, JSON message, when i consume the services,

[http://localhost:8099/json/sum?a=11&b=22](http://localhost:8099/json/sum?a=11&b=22)

should expect below result

{“version”:“1.1”,“result”:“33”}

but it return error as below:

Server Error

The following error occurred:

500 Invalid path specified: ‘/json/sum?a=1&b=2’.

at RemObjects.SDK.Server.IpHttpServerChannel.HandleHttpRequest(Object sender, HttpRequestEventArgs e)  
Framework Version v4.0.30319.34209  
RemObjects SDK for .NET v8.3.91.1167  
Internet Pack for .NET v8.3.91.1167

RemObjects Software, LLC. [remobjects.com](http://remobjects.com).

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [June 11, 2015, 9:03am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/4 "2015-06-11T09:03:41Z")

</div>

Requests where parameters are passed via URL are not supported. You need to pass the request JSON string via request body, not its Url

---

<div class="post-metadata">

### Author: ![wilson](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@wilson](https://talk.remobjects.com/u/wilson)
#### Post date: [June 12, 2015, 4:51am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/5 "2015-06-12T04:51:03Z")

</div>

Hi, i have done some research and most of the way is using URL. Anywhere, i have try to code as below to get the JSON data back, but the server return error. Or might be can you give some code to show how it work ?

```
    protected void btnServerDateTimeJSON_Click(object sender, EventArgs e)
    {
        string urlPath = "http://localhost:8099/json/SUM";

        string data = "A=11&B=22"; //replace <value>
        byte[] dataStream = Encoding.UTF8.GetBytes(data);
        
        WebRequest webRequest = WebRequest.Create(urlPath);
        webRequest.Method = "POST";
        webRequest.ContentType = "application/x-www-form-urlencoded";
        webRequest.ContentLength = dataStream.Length;  
        Stream newStream = webRequest.GetRequestStream();
        // Send the data.
        newStream.Write(dataStream, 0, dataStream.Length);
        newStream.Close();
       
        using (var httpWebResponse = webRequest.GetResponse() as HttpWebResponse)
        {
            if (httpWebResponse != null)
            {
                using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    txtResultJSON.Text = streamReader.ReadToEnd();
                }
            }
        }
    }
```

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [June 12, 2015, 7:26am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/6 "2015-06-12T07:26:21Z")

</div>

Server expexts a JSON string in the request body. Like f.e.

```
{"version":"1.1","method":"ROServer2Service.Sum","params":{"A":3,"B":4}}

```

Then response will be, f.e.

```
{"version":"1.1","result":7}
```

---

<div class="post-metadata">

### Author: ![wilson](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@wilson](https://talk.remobjects.com/u/wilson)
#### Post date: [June 15, 2015, 6:36am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/7 "2015-06-15T06:36:00Z")

</div>

the correct JSON response from server is

{“version”:“1.1”,“result”:{“Result”:33},“id”:"{fe1fe652-bc39-4f25-b66a-b5511c3150e7}"}

for those interested on .net client to read it, you can refer to below code:

c# .net  
var jsonResult = new JavaScriptSerializer().Deserialize(result);  
txtResultJSONGetSum.Text = (jsonResult[“result”][“Result”]).ToString();

Thanks.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [June 15, 2015, 7:08am UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/8 "2015-06-15T07:08:47Z")

</div>

> [@wilson](#):
>
> “version”:“1.1”

This is the JSON message version. Assume it always be 1.1

> [@wilson](#):
>
> “id”:“{fe1fe652-bc39-4f25-b66a-b5511c3150e7}”

This is the remote session Id. Can be useful for authorization tasks.

> [@wilson](#):
>
> “result”:{“Result”:33}

Data payload (server method result).

One can use tools like [http://json2csharp.com/](http://json2csharp.com/) to convert JSON strings into corresponding C# data structures.

---

<div class="post-metadata">

### Author: ![DonaldShimoda](https://talk.remobjects.com/user_avatar/talk.remobjects.com/donaldshimoda/32/6_2.png) [@DonaldShimoda](https://talk.remobjects.com/u/DonaldShimoda)
#### Post date: [December 11, 2018, 2:29pm UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/9 "2018-12-11T14:29:26Z")

</div>

> [@antonk](#):
>
> {“version”:“1.1”,“method”:“ROServer2Service.Sum”,“params”:{“A”:3,“B”:4}}

Any way to get that working as a standard json call?

[http://localhost:8099/json/ROServer2Service/Sum/3/4](http://localhost:8099/json/ROServer2Service/Sum/3/4)

Best regards

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [December 11, 2018, 2:47pm UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/10 "2018-12-11T14:47:45Z")

</div>

Yes. You need to use HttpAPI: [https://talk.remobjects.com/t/new-ro-sdk-feature-http-api/12993](https://talk.remobjects.com/t/new-ro-sdk-feature-http-api/12993)

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [December 11, 2018, 2:51pm UTC](https://talk.remobjects.com/t/how-to-consume-json-ro-web-services/6354/11 "2018-12-11T14:51:46Z")

</div>

another way:  
you can transform this string into valid json request in [HTTPServer.OnCustomResponseEvent](https://docs.remotingsdk.com/API/Delphi/Classes/TROBaseHTTPServer/#OnCustomResponseEvent) event.

see more at [Using OnCustomResponseEvent in a ROSDK Server](https://talk.remobjects.com/t/using-oncustomresponseevent-in-a-rosdk-server/6767) snippet
