Install Service Stack from NuGet
All dependencies will be installed too
After installation, you will several references have been included
On-line document of Service Stack
http://servicestack.net, click the Documentation button
Click Create your first webservice
This page is for non MVC application, so scoll down to the link for MVC
Click the link below:
Copy the content of Web.config
Other steps
Implement in Visual Studio
Add “Api” folder and one class, “HelloService.cs”.
Code separate into 3 parties:
1. Service
2. Request
3. Response, the name is always requestName+Response
Using the service that we just created
Testing on Web Service
The default web site URL has error, it is no doubt
Has to add “/api” to see available web services, but it’s still fail so far
Check the error message, we forgot to new an AppHost() in Application_Start() in Global.asax
So add the code, “new ProteinTrackerAppHost().Init();” in Application_Start() function
Now it works, and showing following screen.
One operation shows, Hello. It supports different format, XML, JSON, JSV, CSV, …etc.
Click JSON, for example.
Two routes are available for this service
Using /api/hello/xxx to consume the web service
In json format
In xml format
沒有留言:
張貼留言