# SOAP::RPC::Driver encoding problem

**URL:** <https://www.ruby-forum.com/t/soap-driver-encoding-problem/159536>\
**Category:** Rails\
**Created:** [February 5, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/soap-driver-encoding-problem/159536 "2009-02-05T14:37:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seurdge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@seurdge](https://www.ruby-forum.com/u/seurdge)\
**Post date:** [February 5, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/soap-driver-encoding-problem/159536/1 "2009-02-05T14:37:32Z")

</div>

Hi,

I have trouble setting a SOAP::RPC::Driver class encoding (for the  
response) to utf-8. My response contains accentuated character that are  
not ok without this. I dont understand why the mandatorychaset= method  
doesnt do the trick so I’m looking for some lights here 😉

Here is my driver class code :

require ‘sw/SecuriteServiceWeb’  
require ‘sw/SecuriteServiceWebMappingRegistry’  
require ‘soap/rpc/driver’

class SecuriteServiceServerPortType \< :🧼:RPC::Driver

DefaultEndpointUrl = $props[RAILS\_ENV][‘securite\_sw\_url’]  
NsSecuriteServiceWeb = “SecuriteServiceWeb”

Methods = [  
[ XSD::QName.new(NsSecuriteServiceWeb, “getUtilisateurXML”),  
“”,  
“getUtilisateurXML”,  
[[“in”, “codeApplication”, [":🧼:SOAPString"]],  
[“in”, “certificat”, [":🧼:SOAPString"]],  
[“retval”, “return”, [":🧼:SOAPString"]] ],  
{ :request\_style =\> :rpc, :request\_use =\> :encoded,  
:response\_style =\> :rpc, :response\_use =\> :encoded,  
:faults =\> {} }  
]  
]

def initialize(endpoint\_url = nil)  
endpoint\_url ||= DefaultEndpointUrl  
super(endpoint\_url, nil)  
self.mapping\_registry =  
SecuriteServiceWebMappingRegistry::EncodedRegistry  
self.literal\_mapping\_registry =  
SecuriteServiceWebMappingRegistry::LiteralRegistry  
init\_methods  
end

private

def init\_methods  
Methods.each do |definitions|  
opt = definitions.last  
if opt[:request\_style] == :document  
add\_document\_operation(\*definitions)  
else  
add\_rpc\_operation(\*definitions)  
qname = definitions[0]  
name = definitions[2]  
if qname.name != name and qname.name.capitalize ==  
name.capitalize  
:🧼:Mapping.define\_singleton\_method(self, qname.name) do  
|\*arg|  
**send** (name, \*arg)  
end  
end  
end  
end  
end  
end

And here is my call method :

```
def obtain_xml_element(tag)

  xml_element = nil

  require 'soap/soap'
  require 'sw/SecuriteServiceWebDriver'
  begin
    driver = SecuriteServiceServerPortType.new

```

#Why is this doest work ?  
driver.mandatorycharset = ‘utf-8’

```
    data_xml = driver.getUtilisateurXML("CDI",

```

cookies[:certificat].to\_s.split(’-’)[0].to\_s)  
data = REXML::Document.new(data\_xml)

```
    if tag.is_a?(Array)
      xml_element = tag.collect {|t| REXML::XPath.first( data, t

```

).to\_s}  
else  
xml\_element = REXML::XPath.first( data, tag ).to\_s  
end

```
  rescue Exception => e
    logger.error $!, $@
    ExceptionNotifier.deliver_exception_notification(e, self,

```

request, {:xml\_element =\> xml\_element, :lacapitale\_certificat =\>  
cookies[:lacapitale\_certificat].to\_s})

```
  ensure
    return xml_element
  end
end

```

Finally, the response looks like :

\<?xml version='1.0' encoding='ISO-8859-1'?\>

1980-12-12  
MACCENT99  
Ãƒâ€°ÃƒÂ©ÃƒÂ¢ÃƒÂ»ÃƒÂ´ÃƒÂ©  
Ãƒâ€°ÃƒÂ©ÃƒÂ¢ÃƒÂ»ÃƒÂ´ÃƒÂ©

Any helps appreciated !

Thx !

Serge S.
