Reputation: 33
I am writing a RESTful web service and have a big trouble in getting the basic step up itself.
I could do the below:
Could create RESTful web service and send and receive the XML (not soap+xml) back to the client with webHttpBinding
Could create RESTful web service and send and receive the soap+xml using the contract as defined below:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml)]
XmlElement PostRequestXML(Stream xmlData);
Is the point (2) is right way to send and receive the soap+xml data?
I did a lots of search on web, but could not find better link which explains the detailed steps on creating web service to send and receive soap+xml.
I would like to know :
what is better way to design my RESTful web service to send and receive soap+xml? Can you show me operation contract definition?
which binding do I need to use? SHare if any example.
OperationContract
and configuring web.config?The request and respond should like as below.
REQUEST:
Header:
POST /EnrollmentServer/Discovery.svc HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
User-Agent: Windows Phone 8 Enrollment Client
Host: EnterpriseEnrollment.Contoso.com
Content-Length: xxx
Cache-Control: no-cache
<?xml version="1.0"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">
http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/Discover
</a:Action>
<a:MessageID>urn:uuid: 748132ec-a575-4329-b01b-6171a9cf8478</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">
https://ENROLLTEST.CONTOSO.COM/EnrollmentServer/Discovery.svc
</a:To>
</s:Header>
<s:Body>
<Discover xmlns="http://schemas.microsoft.com/windows/management/2012/01/enrollment/">
<request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<EmailAddress>[email protected]</EmailAddress>
<RequestVersion>1.0</RequestVersion>
</request>
</Discover>
</s:Body>
</s:Envelope>
RESPONSE:
Header:
HTTP/1.1 200 OK
Content-Length: 865
Content-Type: application/soap+xml; charset=utf-8
Server: EnterpriseEnrollment.Contoso.com
Date: Tue, 02 Aug 2012 00:32:56 GMT
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">
http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/DiscoverResponse
</a:Action>
<ActivityId>
d9eb2fdd-e38a-46ee-bd93-aea9dc86a3b8
</ActivityId>
<a:RelatesTo>urn:uuid: 748132ec-a575-4329-b01b-6171a9cf8478</a:RelatesTo>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">>
<DiscoverResponse
xmlns="http://schemas.microsoft.com/windows/management/2012/01/enrollment">
<DiscoverResult>
<AuthPolicy>OnPremise</AuthPolicy>
<AuthUrl/>
<EnrollmentPolicyServiceUrl>
https://enrolltest.contoso.com/ENROLLMENTSERVER/DEVICEENROLLMENTWEBSERVICE.SVC
</EnrollmentPolicyServiceUrl>
<EnrollmentServiceUrl>
https://enrolltest.contoso.com/ENROLLMENTSERVER/DEVICEENROLLMENTWEBSERVICE.SVC
</EnrollmentServiceUrl>
<FederatedServiceName/>
<FederatedServicePolicy/>
</DiscoverResult>
</DiscoverResponse>
</s:Body>
</s:Envelope>
Upvotes: 1
Views: 1451
Reputation: 41
I have created many WCF API, some of them are REST. My main understanding is - don't use it! WCF is good in enabling you to choose the type of protocol to use between server and client. Using it you pay in performance and durability. If you already set your mind on REST (which is an excellent choice) I suggest you dig into ServiceStack. This is by far the most mature, maintained and advanced REST framework for .NET It is easy to use and helps you build the API correctly, by making many smart choices on the way. Give it a shot and never look back!
Upvotes: 3