typescript - LoopBack 4:向 SOAP 请求中的元素添加类型属性
问题描述
我正在使用 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 的内容(返回错误):
<ns1:change/>
我最初尝试创建类,auto_adjust_item
扩展item_change
,两者都没有任何属性。
lb4 model item_change
然后我使用and将它们创建为模型lb4 model auto_adjust_item
,它变成了ItemChange
and AutoAdjustItem
。AutoAdjustItem
已更改为扩展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'
}
}
更好的是,将其创建为一个类:
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"/>
这感觉像是硬编码命名空间的一个糟糕的解决方法,但它有效,我会接受它。由于严重缺乏支持,我在这一功能上花费了足够的时间。
推荐阅读
- amazon-web-services - Apply multiple tags to an object during uploading via aws cli
- javascript - 如何使用带有 js 的范围滑块旋转对象?
- r - Function summarise in dplyr don't work. Factors are not grouped
- javascript - 如何以角度形式添加动态字段
- c++ - 在 lambda 函数声明中使用 auto
- postgresql - 如何在逻辑复制期间访问触发器函数内的表
- php - 使用 php 下拉菜单调用函数
- java - WireMock:200 个存根工作,但未找到具有服务故障的存根
- google-apps-script - 使用 GAS batchUpdate 将数据从 Google 表格自定义表单上的特定单元格复制到同一电子表格中不同工作表上的特定行
- python - 转置矩阵 Python Pandas