2013年10月13日 星期日

Web Services by Using Service Stack Web Service Framework

Install Service Stack from NuGet

image

All dependencies will be installed too

image

After installation, you will several references have been included

image

 

On-line document of Service Stack

http://servicestack.net, click the Documentation button

image

Click Create your first webservice

image

This page is for non MVC application, so scoll down to the link for MVC

image

Click the link below:

https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework.

image

Copy the content of Web.config

image

Other steps

image

 

Implement in Visual Studio

image

image

image

image

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

image

Using the service that we just created

image

 

Testing on Web Service

The default web site URL has error, it is no doubt

image

Has to add “/api” to see available web services, but it’s still fail so far

image

Check the error message, we forgot to new an AppHost() in Application_Start() in Global.asax

image

So add the code, “new ProteinTrackerAppHost().Init();” in Application_Start() function

image

Now it works, and showing following screen.

One operation shows, Hello. It supports different format, XML, JSON, JSV, CSV, …etc.

Click JSON, for example.

image

Two routes are available for this service

image

Using /api/hello/xxx to consume the web service

image

In json format

image

In xml format

image

沒有留言:

張貼留言