0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Hello! ServiceStack [クライアント編]

Posted at

前回のお話#

旋回はWeb Serviceを作りました。でもWeb Serviceだけあっても意味が無いですよね?
やはり、クライアントと連携しなければ・・・ね・・・。

というわけで今回はクライアント編です。
といっても、ものすごく簡単。Web Service編あんなに長いpostだったのに、ものの数行で終わっちゃうくらいに簡単。

ゴタクはいいからコードを見せろ#

はい、もうコードはこんな感じです。
あ、事前にサービス参照とServiceModelの参照忘れずに。
サービス参照は http://webserver/soap12 みたいな感じでよろしくです。

つーかこの辺りは公式Wikiに載ってる・・・

Program.cs
using System;
using ServiceStack.ServiceClient.Web;
using ServiceStackHelloSample.ServiceModel.Operations;
using ServiceStackHelloSample.ConsoleApp.ServiceStackHelloWebService;

namespace ServiceStackHelloSample.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            JsonServiceClient client = new JsonServiceClient("http://localhost:8080/");
            HelloResponse response = client.Get<HelloResponse>("/hello");
            Console.WriteLine(response.Result.ToString());
            Console.ReadLine();
        }
    }
}

簡単ですね!
上のコードはJSON形式で取るようにしてますが、他にもXMLで取ったりSOAPで取ったりできます。
その辺はもう公式Wiki読んで下さい・・・はい(´・ω・`)


一応、今回のコードはこちらからドウゾ> GitHub : https://github.com/LainZero/ServiceStackHelloSample.ConsoleApp

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?