LoopBack 4:将类型属性添加到 SOAP 请求中的元素

LoopBack 4: Adding type attribute to an element in a SOAP request

我正在使用 LoopBack 4 访问第三方 SOAP API,但我很难让特定的 SOAP 调用正常工作。该文档似乎没有涵盖这种情况。

WSDL 的相关部分:

<xs:element name="change_item">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="change" nillable="true" type="q1:item_change" xmlns:q1="http://schemas.datacontract.org/2004/07/configuration_services"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
...
<xs:complexType name="auto_adjust_item">
    <xs:complexContent mixed="false">
        <xs:extension base="tns:item_change">
            <xs:sequence/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="auto_adjust_item" nillable="true" type="tns:auto_adjust_item"/>
<xs:complexType name="item_change">
    <xs:sequence/>
</xs:complexType>
<xs:element name="item_change" nillable="true" type="tns:item_change"/>

这是从 Java 演示应用程序发送的工作请求中的元素:

<change xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:auto_adjust_item"/>

对于我尝试的一切,这就是 LoopBack 发送到 SOAP 的内容 API(returns 一个错误):

<ns1:change/>

我最初尝试创建 类、auto_adjust_item 扩展 item_change,两者都没有任何属性。

然后我使用 lb4 model item_changelb4 model auto_adjust_item 将它们创建为模型,变成了 ItemChangeAutoAdjustItemAutoAdjustItem 已更改为扩展 ItemChange 而不是 Model。我弄乱了 @model 注释参数,但没有任何帮助。

AutoAdjustItem的一个实例通过参数定义为change: ItemChange的服务接口传递。

有谁知道如何将 type="auto_adjust_item" 属性添加到 SOAP 请求中的元素?

知道了!

参数定义:

change: {
    $attributes: {
        $xsiType: string
    }
}

将其作为参数传递:

const change = {
    $attributes: {
        $xsiType: '{http://schemas.datacontract.org/2004/07/configuration_services}auto_adjust_item'
    }
}

更好的是,将其创建为 class:

export class autoAdjustItem {
    $attributes = {
        $xsiType: '{http://schemas.datacontract.org/2004/07/configuration_services}auto_adjust_item'
    }
}

const change = new autoAdjustItem();

服务器接受的 SOAP 请求中的元素:

<ns1:change xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://schemas.datacontract.org/2004/07/configuration_services" xsi:type="ns2:auto_adjust_item"/>

对于硬编码的命名空间,这感觉像是一个糟糕的解决方法,但它确实有效,我会接受它。由于严重缺乏支持,我已经在这一功能上花费了足够的时间。

我是通过盯着 this documentation, which looks very different from how the tutorial 让我做事而产生尝试这个的想法的。