2

I have created an API using the WSO2 Dataservice which return a JSON Object, My client Application waiting for a SOAP response not a JSON response, so I tried to use datamapper to change the response format from JSON to SOAP but it return only and XML format without the SOAP Body and the SOAP envelope. How to hundle this problem?

This is the SOAP response format I would like to get:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetFacturesClientResponse xmlns="http://tempuri.org/">
<GetFacturesClientResult>
<code>0</code>
<codeClient>P-2008-043681</codeClient>
<nom>na</nom>
<prenom>ouss</prenom>
</GetFacturesClientResult>
</GetFacturesClientResponse>
</soap:Body>
</soap:Envelope>

But I got this response:

<GetFacturesClientResponse xmlns="http://tempuri.org/">
<GetFacturesClientResult>
<code>0</code>
<codeClient>P-2008-043681</codeClient>
<nom>na</nom>
<prenom>ouss</prenom>
</GetFacturesClientResult>
</GetFacturesClientResponse>

And this is my code:

<datamapper config="gov:datamapper/oussama.dmc" inputSchema="gov:datamapper/oussama_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/oussama_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/oussama_xsltStyleSheet.xml"/>
Adam
  • 186
  • 1
  • 4
  • 20
Oussama Nairi
  • 146
  • 1
  • 10

1 Answers1

2

Before the Respond Mediator set the following property.

<property name="messageType" value="application/soap+xml" scope="axis2"/>

Also in your Datamapper section the outputType="XML" not JSON.


Update

As ophychius mentioned. The above content type will create a SOAP 1.2 message and if you need a SOAP 1.1 message set the content type to text/xml. Typically, clients supports both versions.

ycr
  • 12,828
  • 2
  • 25
  • 45
  • 1
    The namespace in the desired message is soap 1.1, which would require a messageType of "text/xml". AFAIK the above messageType will lead to a default soap 1.2 envelope. – ophychius Dec 12 '22 at 14:40
  • @ophychius yes that's correct. I added the details to the answer to make it complete. – ycr Dec 12 '22 at 14:48