My favorites
▼
|
Sign in
servicestack
Open Source .NET Framework for rapidly developing REST-full XML, JSON and WCF SOAP web services
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
doc
/
UsageExamples
/
UsingRestAndJson.cs
r1374
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.IO;
using System.Net;
using NUnit.Framework;
using Sakila.ServiceModel.Version100.Types;
using ServiceStack.ServiceModel.Serialization;
using ServiceStack.UsageExamples.Support;
using DtoOperations = Sakila.ServiceModel.Version100.Operations.SakilaService;
namespace ServiceStack.UsageExamples
{
[TestFixture]
public class UsingRestAndJson : TestBase
{
[Test]
public void Get_customers_using_rest_and_json()
{
var requestUri = string.Format("{0}/{1}?CustomerIds={2}",
JsonSyncReplyBaseUri, typeof(DtoOperations.GetCustomers).Name, CustomerId);
var client = WebRequest.Create(requestUri);
var json = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
var response = JsonDataContractDeserializer.Instance.Parse(json,
typeof(DtoOperations.GetCustomersResponse)) as DtoOperations.GetCustomersResponse;
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Customers.Count);
Assert.AreEqual(CustomerId, response.Customers[0].Id);
}
[Test]
public void Get_customers_using_json_post()
{
var request = new DtoOperations.GetCustomers { CustomerIds = new ArrayOfIntId(new[] { base.CustomerId }), };
var jsonRequest = JsonDataContractSerializer.Instance.Parse(request);
var requestUri = JsonSyncReplyBaseUri + "/" + typeof(DtoOperations.GetCustomers).Name;
var client = WebRequest.Create(requestUri);
client.Method = "POST";
client.ContentType = "application/json";
using (var writer = new StreamWriter(client.GetRequestStream()))
{
writer.Write(jsonRequest);
}
var json = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
var response = JsonDataContractDeserializer.Instance.Parse(json,
typeof(DtoOperations.GetCustomersResponse)) as DtoOperations.GetCustomersResponse;
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Customers.Count);
Assert.AreEqual(CustomerId, response.Customers[0].Id);
}
}
}
Show details
Hide details
Change log
r398
by demis.bellot on Oct 14, 2009
Diff
re add UsageExamples
Go to:
/trunk/doc
/trunk/doc/UsageExamples
/trunk/doc/UsageExamples/Lib
...k/doc/UsageExamples/Lib/wget.exe
/trunk/doc/UsageExamples/Properties
...mples/Properties/AssemblyInfo.cs
...eExamples/Properties/DataSources
...ion100.Types.Customer.datasource
....Types.ResponseStatus.datasource
/trunk/doc/UsageExamples/README.txt
...UsageExamples/Service References
... References/BasicHttpClientProxy
...asicHttpClientProxy/Reference.cs
...HttpClientProxy/Reference.svcmap
...pClientProxy.Customer.datasource
...lientProxy.Properties.datasource
...tProxy.ResponseStatus.datasource
...BasicHttpClientProxy/Soap11.wsdl
...lientProxy/configuration.svcinfo
...entProxy/configuration91.svcinfo
...ice References/WsHttpClientProxy
...s/WsHttpClientProxy/Reference.cs
...HttpClientProxy/Reference.svcmap
...pClientProxy.Customer.datasource
...lientProxy.Properties.datasource
...tProxy.ResponseStatus.datasource
...es/WsHttpClientProxy/Soap12.wsdl
...lientProxy/configuration.svcinfo
...entProxy/configuration91.svcinfo
...erviceStack.UsageExamples.csproj
...eStack.UsageExamples.csproj.user
/trunk/doc/UsageExamples/Support
...sageExamples/Support/TestBase.cs
...sageExamples/Support/Translators
...ranslators/CustomerTranslator.cs
...sicHttpServiceReferenceClient.cs
...Examples/UsingDtoFromAssembly.cs
...UsageExamples/UsingDtoFromXsd.cs
...geExamples/UsingRawHttpClient.cs
...sageExamples/UsingRestAndJson.cs
...UsageExamples/UsingRestAndXml.cs
...eExamples/UsingServiceClients.cs
...s/UsingServiceReferenceClient.cs
...s/UsingSvcutilGeneratedClient.cs
/trunk/doc/UsageExamples/app.config
/trunk/doc/UsageExamples/svc
...xamples/svc/GenerateSvcProxy.bat
...c/UsageExamples/svc/Service.wsdl
...amples/svc/SvcSyncReplyClient.cs
.../UsageExamples/svc/output.config
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2013 bytes, 55 lines
View raw file
Powered by
Google Project Hosting