Expose REST API as SOAP via Azure API Management

不羁岁月 提交于 2021-01-28 11:57:20

问题


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?

I have seen plenty of posts about exposing SOAP services as REST API, but not the other way around.


回答1:


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.

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; }
}
  • 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.


来源:https://stackoverflow.com/questions/52769635/expose-rest-api-as-soap-via-azure-api-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!