Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
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:
C#
public class Sub
{
public string HostUID { get; set; }
public string HostName { get; set; }
}


web service method of type:
public string Method1(Sub input);
Posted
Comments
SASS_Shooter 5-Jul-12 17:04pm    
-1 on both questions for posting duplicates

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.
 
Share this answer
 
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.

RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)

Call fro JSON must be of type as below:

Java
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"); 
			conn.setChunkedStreamingMode(0); 
			conn.setDoInput(true);
			conn.setDoOutput(true);
			conn.setRequestMethod("POST"); 
			conn.connect(); 
			DataOutputStream out = new DataOutputStream(conn.getOutputStream()); 
			out.write(jo1.toString().getBytes()); 
			out.flush();  
			int code = conn.getResponseCode(); 
			String message = conn.getResponseMessage(); 
			InputStream in1 = conn.getInputStream();
			StringBuffer sb = new StringBuffer();
			String reply1; 
			try { int chr; while ((chr = in1.read()) != -1) { sb.append((char) chr); }
			reply1 = sb.toString(); }
			finally { in1.close(); }
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900