Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All ,

Can I use soap requests Restful Web API ?

I have a basic authentication and need to send ProductID in the request .

the request should be like below:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <UserDetails xmlns="http://tempuri.org/">
      <username>testuser</username>
      <password>pass123</password>
    </UserDetails>
  </soap:Header>
  <soap:Body>
    <GetProductsbyId xmlns="http://tempuri.org/">
      <id>12</id>
    </GetProductsbyId>
  </soap:Body>
</soap:Envelope>


I tried this format and returning 401 unauthorised error.

Do I need to create WCF /WEBSERVICE for this request format ?
Note: This request working in Webservice verywell. My question is whether it will in Restful WEB API ?

What I have tried:

I created a webservice t(asmx) and this request working fine there. But Can use this it WEBAPI ?
Posted
Updated 15-Oct-17 21:25pm

1 solution

Yes - in theory you can use SOAP envelopes in a RESTfull API (and that because SOAP is a protocol and REST is architectural definition without claiming the use of any specific protocol)... However in our reality the actual templates to create RESTfull API (for instance in VS) does not support it and for that you will have to do a lot of hand-writing to fill the gaps...
In any case it is not needed (and advised) to use SOAP with REST, as both have different purposes...
To make the right decision you should first understand the differences and usage of both...
Understanding SOAP and REST Basics And Differences[^]
 
Share this answer
 
Comments
ali_1 16-Oct-17 4:00am    
Thanks Peter! You explained it well..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900