3
votes

I've built and api in nodejs with the library "soap" that consumes a wsdl project.

Im trying to do a post and in the response body im 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:

  1. when creating soap client added forceSoap12Headers:false and viceverse
  2. rewrite soap library with accept content and content-type to: text/xml; charset=utf-8, also change all schemes that belongs to soap v1.1
  3. try do add httpHeader 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)
                }
            }

                }
            })
3
I'm actually suprise that someone is still using SOAP.Nicolas
any idea what is happening here? Im stuckEleazar
I'm not familiar with how to setup soap, but it seams like your server cannot access text/xml. And that's what your front-end is sending. Maybe add text/xml as accepted content type to your server headers ?Nicolas
or try to add content-type: application/soap+xml as your request content type.Nicolas
I tried to override headers in http libray that cames as dependecy of soap library, but still getting same error...Eleazar

3 Answers

8
votes

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!!

1
votes

For me,

  1. I went to headers, deselected the original Content-type
  2. Then went to presets, clicked manage presets
  3. There, I clicked Add, then in the popup
    a. Choose a Header Preset Name (anything will work)
    b. For key -- enter Content-type
    c. For value -- enter text/xml
    d. Last click Add at bottom right corner
  4. Close the manage preset popup
  5. Click your new preset, then select the new Content-type at the bottom
0
votes

Here'e what I got to fix the error in my case. Go to Headers first: then if you can be able to change, right at the spot, the default content-type value from application/xml to text/xml try edit that first. If not uncheck content-type checkbox and in the same column at the bottom just type content-type for the Key and text/xml for the value. Then it works perfect !!!