views:

39

answers:

2

Hi frnds.... I have tiered of Googling but did't get any clue for myself. I want to make a web service which will have any method (let say-ProductInfo) & when i pass a productId in this method this will return the entire information of Product(like-ProdName,ProdPrice etc) in JSON format(File is downloaded with the Information of product).

I am very new ....so please guide me as a beginner for the above. for any kind of help Millions of Thanks.

+1  A: 

For WCF (which is the recommended way of developing web service on .NET) you may take a look at this article for an example of developing a web service exposing JSON data.

For plain old ASMX services you could use the [ScriptService] attribute. Here's another article which illustrates the concept with an example.

Darin Dimitrov
I want output something like in this manner-http://209.62.6.226/GracoRest/service.svc/Rest/WheretoBuy
So the links I've posted might help you get started. Don't hesitate to ask if you encounter problems implementing some specific part.
Darin Dimitrov
thanks Dimitrov...i will catch u tommarrow ....now i m at home.
Hi darin....please help me for this.I have a method in my wcf service "ProductDetails" which takes 1 argument productId(string)...which returns product details to me.This methos is working fine when i do-http://192.xx.x.xx./Abc/Service.svc/ProductDetailsIt returns a file with contents in JSON format.now i want to call this method in Iphone....i m doing this-NSString *url=[NSString stringwithFormat:@"http://192.xx.x.xx./Abc/Service.svc/ProductDetails/%@","@P2"]Let the value of prodId is P2....This does't give me the right output.so please something for the above..where i m doing wrong.
+1  A: 

Base on your tag. I guess you use ASP.NET MVC. however, it you mean class ASP.NET then you might need to use WCF-REST to return JSON.

So: for you starting point

  • ASP.NET MVC - look at JsonResult here >>
  • ASP.NET - look at WCF-RESThere >>

Or if you are very new and don't know where to start, I'm recommended you to start at ASP.NET MVC 2

Jirapong
Hi thanks again.. But i have problem.. i have gone through...ASP.NET - look at WCF-RESThere >> It is creating the service (localhost:2456/HTTPServiceJquery/service/…) but how i will access the methods of this service?? when i do this- (localhost:2456/HTTPServiceJquery/service/…) It results into method not allowed. so i want to use this methos of the service...plz tell me how i will do this. Sorry if it is a stupidity ...but i am anable to do this.I want something in this manner-http://209.62.6.226/GracoRest/service.svc/Rest/WheretoBuy
No, You're not stupid. everyone passed this. You must create WCF inside you ASP.NET project. because JSON/Javascript request not allow you to call cross-domain.
Jirapong
would you refer me some link(help) that will help me for doing this step by step.Thanks again.
Unfortunally, There is no easy way - step by step that i can find. but first you need to have .svc in your project configure with web.config. http://www.itscodingtime.com/post/The-different-ways-to-host-a-WCF-Service-Application-in-a-Web-App.aspx might help. then you need to use Attribute WebInvoke which all good resource you can read at - http://www.west-wind.com/Weblog/ShowPosts.aspx?Category=WCFI encourage you to use WCF because later on it will be what all use can use. Silverlight, jQuery, WinPhone7 etc.
Jirapong
Hi Jirapong...I have solved my problem discussed above.But now there is one other....I have a method in my wcf service "ProductDetails" which takes 1 argument productId(string)...which returns product details to me.This methos is working fine when i do-http://192.xxx.xxx.xx./Abc/Service.svc/ProductDetailsIt returns a file with contents in JSON format.now i want to call this method in Iphone....i m doing this-NSString *url=[NSString stringwithFormat:@"http://192.xxx.xxx.xx./Abc/Service.svc/ProductDetails/%@","@P2"]Let the value of prodId is P2....This does't give me the right output.
so please suggest something for the above..where i m doing wrong.
There are two things.1. You need to make Http Call instead of like that - http://www.mobileorchard.com/tutorial-json-over-http-on-the-iphone/2. You need a JSON Library - Go here and do Option 1 http://code.google.com/p/json-framework/wiki/InstallationInstructions
Jirapong
Thanks exactly that i was looking for.