12

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)
                }
            }

                }
            })
Eleazar
  • 335
  • 1
  • 3
  • 10
  • 1
    I'm actually suprise that someone is still using SOAP. – Nicolas Nov 29 '19 at 18:30
  • any idea what is happening here? Im stuck – Eleazar Nov 29 '19 at 18:32
  • 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 Nov 29 '19 at 18:34
  • 1
    or try to add `content-type: application/soap+xml` as your request content type. – Nicolas Nov 29 '19 at 18:35
  • I tried to override headers in http libray that cames as dependecy of soap library, but still getting same error... – Eleazar Nov 29 '19 at 18:37
  • @Nicolas sadly for us, some under-the-radar companies and developers still use it – zyrup Sep 13 '21 at 19:03
  • 1
    @zyrup I guess it should not suprise me. I mean, some mainframes are still running on COBOL, SOAP is the internet data transfer protocol equivalent of COBOL. – Nicolas Sep 14 '21 at 12:56

3 Answers3

18

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

Eleazar
  • 335
  • 1
  • 3
  • 10
7

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
voltsrage
  • 71
  • 1
  • 1
  • This worked perfectly. I wonder why adding Content-Type directly as a key didn't work but using this preset does... – Izulien May 18 '21 at 15:20
2

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

Tes
  • 151
  • 1
  • 7