通过Azure API管理将REST API公开为SOAP [英] Expose REST API as SOAP via Azure API Management

查看:63
本文介绍了通过Azure API管理将REST API公开为SOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一套现有的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.

您将必须使用API​​M策略编写自己的转换逻辑.这是您需要做的几件事:

You will have to write your own transformation logic using APIM policies. Here are a few things you will need:

  • 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屋!

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