I've built and API in nodejs with the library "soap" that consumes a wsdl project.
I'm trying to do a post and in the response body I'm getting this error:
The server cannot service the request because the media type is unsupported
also in the response body I have this message:
Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8.
I did some research and figure it out that is a problem of soap version between server and client.
I try this things:
forceSoap12Headers:false
and viceversetext/xml; charset=utf-8
, also change all schemes that belongs to soap v1.1httpHeader
in request 'Accept' 'text/xml'
This is part of my code:
MethodTest: async function(wsdl){
try{
var client = soap.createClient(wsdl,{forceSoap12Headers:false},async (err,result)=>{
if(err){
}else{
var descripcion = await this.ServiceDescription(wsdl);
if(!descripcion.error){
var body = { _xml: "<i0:GetAccountBalance>"+
"<i0:dc>"+
"<i0:RequestId>000</i0:RequestId>"+
"<i0:SystemId>WEB</i0:SystemId>"+
"<i0:SourceId>AR</i0:SourceId>"+
"<i0:AccountNumber>42526372</i0:AccountNumber>"+
"</i0:dc>"+
"<i0:dcSecurity>"+
"<i0:WebUser>NDsVwQwRbwbuY / DcX2PRGw ==</i0:WebUser>"+
"<i0:WebPassword>/d8zOcR9K9xqpl8CdhUJrw==</i0:WebPassword>"+
"</i0:dcSecurity>"+
"</i0:GetAccountBalance>"}
try{
var response = await (result[descripcion.metodos[8]+"Async"])(body)
}catch (e){
console.log(e.response)
}
}
}
})
I found it. I Had two problems, when creating the client service the default endpoint was set wrong and required the Content-Type application/soap+xml; charset=utf-8. I just Override the endpoint and the request went OK!!