I have the following WSDL definition:
<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SoapQuery">
<part name="TransType" type="xsd:string" />
</message>
<message name="SoapQueryResult">
<part name="ResponseCode" type="xsd:string"/>
<part name="ResultDesc" type="xsd:string" />
</message>
<portType name="SoapQuery_PortType">
<operation name="SoapQuery">
<input message="SoapQuery" />
<output message="SoapQueryResult" />
</operation>
</portType>
<binding name="SoapQuery_Binding" type="SoapQuery_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="SoapQuery" style="document">
<soap:operation soapAction="SoapQuery" />
<soap:input>
<soap:body namespace="app" use="literal" />
</soap:input>
<soap:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
</soap:output>
</operation>
</binding>
<service name="SoapQueryService">
<documentation>WSDL File for SoapQueryService</documentation>
<port binding="SoapQuery_Binding" name="SoapQuery_Port">
<soap:address location="http://localhost:8002/api/request" />
</port>
</service>
</definitions>
and the following handler definition:
var SoapQueryService = {
SoapQueryService: {
SoapQuery_Port: {
// This is how to define an asynchronous function.
SoapQuery: function (args, callback) {
// do some work
callback({
'ResultCode': 0,
'ResultDesc': "sdfds",
});
}
}
}
};
Currently, when receiving the following request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<app:SoapQuery xmlns:app="http://app.com/app">
<TransType>11124</TransType>
</app:SoapQuery>
</soapenv:Body>
</soapenv:Envelope>
it returns:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:app="http://app.com/app">
<soap:Body>
<app:SoapQueryResponse>
<app:ResultCode>0</app:ResultCode>
<app:ResultDesc>sdfds</app:ResultDesc>
</app:SoapQueryResponse>
</soap:Body>
</soap:Envelope>
But I want the response to look like:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:app="http://app.com/app">
<soap:Body>
<app:SoapQueryResult> <!-- not - SoapQueryResponse -->
<ResultCode>0</ResultCode> <!-- notice there is no `app:` -->
<ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
</app:SoapQueryResult>
</soap:Body>
</soap:Envelope>
I have tried different approaches but none to seem to have effect on the response type. I feel like I am missing something in the WSDL or the handler..
Omit the
RPCtag in your WSDL definition and change it from<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>to
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />because you're using
RPCas style it's addingapp:to the output message and the parts, ignoring youroutputNameand replacing it withSoapQueryResponseas well. Removing theRPCtag will give you this outputBy default
node-soapwill remove alltargetNamespaceprefix from the message and message parts if is not stylizedRPC. I have created a pull request here which will allow users to add optionaltargetNamespaceon the output message to be prefixed on the output only not the parts. So with the suggested pull request, you'd addtargetNamespaceto your messageand you'll get your desired output