我可以在REST WEB API中使用SOAP请求吗? [英] Can I user SOAP request in REST WEB API

查看:83
本文介绍了我可以在REST WEB API中使用SOAP请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我可以使用soap请求Restful Web API吗?



我有基本身份验证,需要在请求中发送ProductID。



请求应如下所示:

<?xml version =1.0encoding =utf -8\" >?; 
< soap:Envelope xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns:xsd =http://www.w3.org/2001/XMLSchemaxmlns :肥皂= 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>





我试过这种格式并返回401未经授权的错误。



我是否需要为此请求格式创建WCF / WEBSERVICE?

注意:此请求在Webservice中工作非常好。我的问题是它是否会在Restful WEB API中?



我尝试过:



我创建了一个webservice t(asmx),这个请求在那里工作正常。但是可以使用WEBAPI吗?

解决方案

是的 - 从理论上讲,你可以在RESTfull API中使用SOAP信封(因为SOAP是一种协议而REST是架构定义没有声称使用任何特定的协议)...但是在我们的现实中,创建RESTfull API的实际模板(例如在VS中)不支持它,为此你将不得不做大量的手写来填补差距......

在任何情况下都不需要(并建议)将SOAP与REST一起使用,因为它们都有不同的用途...

做出正确的决定你应该先了解两者的差异和用法...

了解SOAP和REST基础知识和差异 [ ^ ]

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 ?

解决方案

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[^]


这篇关于我可以在REST WEB API中使用SOAP请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆