Click here to Skip to main content
12,820,521 members (29,090 online)
Rate this:
Please Sign up or sign in to vote.
How to write WCF service in JSON and call the same from Java Android app???

And the WCF JSON service input must be of type user defind object as of below:
public class Sub
public string HostUID { get; set; }
public string HostName { get; set; }

web service method of type:
public string Method1(Sub input);
Posted 5-Jul-12 4:06am
SASS_Shooter 5-Jul-12 17:04pm
-1 on both questions for posting duplicates
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well...first of all you do NOT write WCF services in JSON! You (hopefully) write your services in C#. JSON is just one of many forms of serializing data to pass across the wire.

If you are asking how to write a WCF service, you could start with an article like
this[^]. It gives a good process for writing your first service. Once your service is running and your tests for your services work, then you are ready for the next step.

Then once you have written your service you read and follow an article like this[^].

However if you are asking someone here to write your service for you....

... excuse me because I can't stop laughing.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I got to know that there is nothing to write seperately in WCF for JSON..We have to just keep the this as a tag fro the response to be in JSON.


Call fro JSON must be of type as below:

URI uri = new URI("Http://...."); 
			JSONObject jo1 = new JSONObject();
			jo1.put("Id", "12");
			jo1.put("StringValue", "as");
			HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
			conn.setRequestProperty("Content-Type","application/json; charset=utf-8"); 
			conn.setRequestProperty("Accept", "application/json");
			conn.setRequestProperty("User-Agent", "Pigeon"); 
			DataOutputStream out = new DataOutputStream(conn.getOutputStream()); 
			int code = conn.getResponseCode(); 
			String message = conn.getResponseMessage(); 
			InputStream in1 = conn.getInputStream();
			StringBuffer sb = new StringBuffer();
			String reply1; 
			try { int chr; while ((chr = != -1) { sb.append((char) chr); }
			reply1 = sb.toString(); }
			finally { in1.close(); }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 6 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100