我正在使用node-soap与现有的 SOAP API 进行交互。我遇到了多个模式和命名空间的问题,从我正在阅读的内容来看,这可能是一个已知问题。这是设置,我正在与一个具有两个模式的 WSDL 文件交互:
WSDL(为简洁起见删除了属性和元素):
<wsdl:definitions xmlns:tns="[rm-nsurl]" targetNamespace="[rm-nsurl]" ...>
<!-- schema1 -->
<schema xmlns:tns="[cm-nsurl]" targetNamespace="[cm-nsurl]" ...>
<complexType abstract="true" name="Operation">
<sequence>
<element maxOccurs="1" minOccurs="0" name="operator" type="tns:Operator">...</element>
</sequence>
</<complexType
</schema>
<!-- schema2 -->
<schema xmlns:cm="[cm-nsurl]" xmlns:tns="[rm-nsurl]" targetNamespace="[rm-nsurl]" ...>
<complexType name="UserListOperation">
<complexContent>
<extension base="cm:Operation">...</extension>
</complexContent>
</complexType>
</schema>
...
</wsdl:definitions>
重要的细节是这两个模式定义tns
为不同的值。当 schema2 中的类型引用 schema1 ( cm:Operation
) 中的元素时,它使用 cm 的显式命名空间(到目前为止很好),但是然后跳转到 schema1 中引用的类型,我们现在看到tns
使用的命名空间,而在 schema1tns
中是cm
。这会导致问题,因为 node-soap 正在使用单个整体值tns
,在这种情况下恰好是rm
,并且在需要时它没有显式使用cm
命名空间。
这是我看到问题的示例:
传递给 WSDL 方法的请求对象:
{
operations: [{
operator: 'SET',
operand: {
id: 'abcd1234',
description: 'a description'
}
}]
};
Node-soap 生成的请求 XML:
<soap:Envelope xmlns:tns="[rm-nsurl]" xmlns:cm="[cm-nsurl]" ...>
<soap:Body>
<mutate xmlns="[rm-nsurl]">
<operations>
<operator>SET</operator>
<operand><id>abcd1234</id><description>a description</description></operand>
</operations>
</mutate>
</soap:Body>
</soap:Envelope>
请求错误
[OperatorError.OPERATOR_NOT_SUPPORTED @ operations[0], RequiredError.REQUIRED @ operations[0].operator]
我可以通过在 readme 中提到operator
的请求对象中手动包含元素的 cm 命名空间来解决这个问题。我想知道在这种情况下是否有更好的方法来使用 node-soap,因为所有必需的信息都在 WSDL 中指定,或者我遇到了 node-soap 关于命名空间的问题之一?
这是与解决方法相同的请求对象:
{
operations: [{
'cm:operator': 'SET',
operand: {
id: 'abcd1234',
description: 'a description'
}
}]
};
具体细节:这是我正在使用的 WSDL。我在使用mutate
操作时遇到了这个问题,它是operator
命名空间不正确的元素。