【发布时间】:2020-12-12 07:32:35
【问题描述】:
我正在使用 SOAP npm 模块来创建 SOAP 服务器。然后使用soap模块将下面的模块绑定到/wsdl端点。
var dns = require('dns');
export default {
MyService: {
MyServicePortType: {
MyFunction: function(args, callback) {
console.log(args);
if(!args.domain) {
return {
ip: 'Please pass a domain name like google.com'
}
}else {
dns.lookup(args.domain, function (err, addresses, family) {
console.log(addresses, family);
callback({
ip: addresses
});
});
}
}
}
}
};
这是我正在使用的 WSDL
<wsdl:definitions name="MyService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://localhost:3000/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://localhost:3000/wsdl">
<wsdl:documentation>MyService</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://localhost:3000/wsdl">
<xs:element name="IpRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="domain" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="IpResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ip" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="domainRequest">
<wsdl:part name="parameters" element="ns:IpRequest" />
</wsdl:message>
<wsdl:message name="domainResponse">
<wsdl:part name="parameters" element="ns:IpResponse" />
</wsdl:message>
<wsdl:portType name="MyServicePortType">
<wsdl:operation name="MyFunction">
<wsdl:input message="ns:domainRequest" />
<wsdl:output message="ns:domainResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyServiceHttpBinding" type="ns:MyServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="MyFunction">
<soap:operation soapAction="http://localhost:3000/wsdl/MyFunction" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyService">
<wsdl:port name="MyServiceHttpsEndpoint" binding="ns:MyServiceHttpBinding">
<soap:address location="http://localhost:3000/wsdl" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
当我从邮递员发出 SOAP 请求时,它会给出空的肥皂体作为响应,
请求
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://localhost:3000/wsdl">
<soap:Body>
<ns:IpRequest>
<ns:domain>yahoo.com</ns:domain>
</ns:IpRequest>
</soap:Body>
</soap:Envelope>
回应
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://localhost:3000/wsdl">
<soap:Body/>
</soap:Envelope>
MyFunction 中的Console.log 语句也没有执行。是因为 WSDL 或 soap 请求有问题吗?
【问题讨论】:
标签: node.js web-services soap wsdl