I'm wondering if I'm missing something obvious, so please help me if you can.
All the tutorials and sample Web API projects are very useful, however I noticed that they all incorporate the client-side (i.e. chtml and jquery calls) in the same project.
If I truly want to separate my web api from the client, how do I publish a Web API service for other .net projects to consume ?
I don't have much experience with .net services, hence I may be missing something obvious - so please excuse me.
A shared models assembly, as noted by @digitalpacman, should work. If you are looking for something more like the SOAP coupling offered by WCF, you could take a look at hosting HttpServer in a WindowsService. HttpServer is the base for both selfhost and
webhost, but it will not run formatters by default. You'll still need to share a models assembly for this to work.
I hear the video presenter mentioned the term "service" from time to time, but there's never any mention of how to publish that service for clients to consume. i.e. I only see jow jquery calls into the controllers, and subsequently how jquery then receives
back the JSON-formatted data to be rendered on the client.
One suggestion I'm hearing here is to publish a DLL, and another is to use WCF-style services.
In the end, what is the real advantage by using Web API versus say a straight asp.net mvc 4 project to build my website ?
Thanks again for your patience in helping me to understand.
I hear the video presenter mentioned the term "service"
robertmazzo
I only see jow jquery calls into the controllers, and subsequently how jquery then receives back the JSON-formatted data to be rendered on the client.
The fact is that jquery calls are just client requests from a browser. You can do the same from any .NET projects using HttpContent class ('System.Net.Http.Formatting' nuget package) or simply native WebClient/WebRequest classes. What your .NET client projects
need is just a resource(url). A resource might be refer an ASP.NET host(IIS, Cassini, IIS-Expresss, etc) or Self Host(Console, Windows, WPF, Windows
Service, etc). For self hosting here is a
great example,.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
robertmazzo
Participant
1030 Points
347 Posts
How to publish a Web API service for other .net projects to consume
Apr 20, 2012 04:16 PM|LINK
Hello,
I'm wondering if I'm missing something obvious, so please help me if you can.
All the tutorials and sample Web API projects are very useful, however I noticed that they all incorporate the client-side (i.e. chtml and jquery calls) in the same project.
If I truly want to separate my web api from the client, how do I publish a Web API service for other .net projects to consume ?
I don't have much experience with .net services, hence I may be missing something obvious - so please excuse me.
thanks in advance.
Bob
digitalpacma...
Member
183 Points
148 Posts
Re: How to publish a Web API service for other .net projects to consume
Apr 20, 2012 04:43 PM|LINK
All the examples would work just fine in outside projects.
If you are asking how server-2-server they would know of your data types, you can have a published DLL that has all the types they will need in it.
panesofglass
Member
730 Points
237 Posts
Re: How to publish a Web API service for other .net projects to consume
Apr 20, 2012 06:13 PM|LINK
A shared models assembly, as noted by @digitalpacman, should work. If you are looking for something more like the SOAP coupling offered by WCF, you could take a look at hosting HttpServer in a WindowsService. HttpServer is the base for both selfhost and webhost, but it will not run formatters by default. You'll still need to share a models assembly for this to work.
robertmazzo
Participant
1030 Points
347 Posts
Re: How to publish a Web API service for other .net projects to consume
Apr 20, 2012 06:51 PM|LINK
Thank you for those two responses, folks.
I hear the video presenter mentioned the term "service" from time to time, but there's never any mention of how to publish that service for clients to consume. i.e. I only see jow jquery calls into the controllers, and subsequently how jquery then receives back the JSON-formatted data to be rendered on the client.
One suggestion I'm hearing here is to publish a DLL, and another is to use WCF-style services.
In the end, what is the real advantage by using Web API versus say a straight asp.net mvc 4 project to build my website ?
Thanks again for your patience in helping me to understand.
regards,
Bob
imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: How to publish a Web API service for other .net projects to consume
Apr 21, 2012 02:29 PM|LINK
The fact is that jquery calls are just client requests from a browser. You can do the same from any .NET projects using HttpContent class ('System.Net.Http.Formatting' nuget package) or simply native WebClient/WebRequest classes. What your .NET client projects need is just a resource(url). A resource might be refer an ASP.NET host(IIS, Cassini, IIS-Expresss, etc) or Self Host(Console, Windows, WPF, Windows Service, etc). For self hosting here is a great example,.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD