通过Azure API管理将REST API公开为SOAP [英] Expose REST API as SOAP via Azure API Management
问题描述
我们有一套现有的REST API(.NET Core).我们希望通过使用Azure API管理将这些API公开为SOAP服务.这可能吗?
We have an existing set of REST APIs (.NET Core). We have a requirement to expose these APIs as SOAP services, hopefully by using the Azure API Management. Is this possible?
我已经看到很多关于将SOAP服务公开为REST API的文章,但并非相反.
I have seen plenty of posts about exposing SOAP services as REST API, but not the other way around.
推荐答案
当您将SOAP API作为APIM中的REST时,它所做的就是创建一堆策略以供操作以动态处理请求/响应有效负载并将JSON转换为XML.即使没有向导来创建反向转换-当然也可以.
When you SOAP API as REST in APIM all it does is creates a bunch of policies for operations to process request/response payload on the fly and convert JSON to XML. Even though there is no wizard to create transformations for reverse - that is surely possible.
您将必须使用APIM策略编写自己的转换逻辑.这是您需要做的几件事:
You will have to write your own transformation logic using APIM policies. Here are a few things you will need:
- 设置主体策略 https://docs.microsoft.com/zh-cn/azure/api-management/api-management-transformation-policies#SetBody 可以用XML和其他方式替换JSON bosy.看到它支持Liquid模板,可能会派上用场.
- 未记录(出于某种原因),但是可以在策略表达式中使用context.Request.Body.AsSoap()获取当前请求的ISoapMessage(与Response相同).这是此界面:
- set-body policy https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBody to replace JSON bosy with XML and other way around. See that it supports Liquid templates, that may come in handy.
- It's not documented (for some reason), but in policy expressions you can use context.Request.Body.AsSoap() to obtain ISoapMessage of current request (same for Response). Here is this interface:
public enum SoapVersionLiteral
{
Soap11,
Soap12
}
public interface ISoapMessage
{
SoapVersionLiteral Version { get; set; }
string Action { get; set; }
IEnumerable<ISoapHeader> Headers { get; set; }
ISoapBody Body { get; set; }
}
public interface ISoapHeader
{
XName Name { get; }
string Value { get; }
Uri Actor { get; }
bool MustUnderstand { get; }
}
public interface ISoapBody
{
XName Name { get; }
XElement Contents { get; }
}
- 您可以尝试在野外找到一些WSDL,并将它们作为SOAP导入APIM中的REST,以查看创建了什么样的策略以将XML转换为JSON进行响应并将JSON转换为XML进行请求.
- You could try to find some WSDLs in the wild and import them as SOAP to REST in APIM to see what kind of policies are created to transform XML to JSON for responses and JSON to XML for requests.
这篇关于通过Azure API管理将REST API公开为SOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!