From: Ernest Ellingson Date: 2005-04-06T08:56:01+09:00 Subject: Re: [howto] pass a byte array to a web service aastanti@hotmail.com wrote: > Hello all, > > I have a web service developed in java with axis and I'd like to invoke > it by means of SOAP4R. The problem is that I don't know how to pass an > array of bytes, without starting from the WSDL. I tried with > String#pack, an array with numbers or chars (ie: [121] or ['a'] or > [65.chr]), but they all fail. > > On customer side I always get: > SOAP::FaultError: java.lang.IllegalArgumentException: argument type > mismatch > from # > > Please consider that the argument is defined in wsdl as: > > ("x" is obviously a fake name) > > I tried simply with String as well, but I get: > SOAP::FaultError: org.xml.sax.SAXException: Bad types (class > java.lang.String -> > class [B) > from # > > We tried calling the web service in the following way: > require 'soap/rpc/driver' > s = > SOAP::RPC::Driver.new('http://localhost:8080/fake/services/BigFake', > 'http://www.fake.com/fake') > s.add_method_with_soapaction("fakeMethod", > 'http://localhost:8080/fake/services/BigFake/fakeMethod', ['in', 'x']) > x = ['a'] > p s.fakeMethod(x) > > Of course in reality we are calling a more complex method, with 8 input > parameters, 1 output parameter and a return value, but we have problem > only with the byte[] one. > > The equivalent java version (the one that works) is a lot more complex, > hence it is not useful to post it here, but consider that the parameter > is passed to an axis call client as a native byte[]. > > We have tried to invoke the web service starting from the WSDL, and > surprisingly it works passing a String, which is not so understandable > to me: > require 'soap/wsdlDriver' > WSDL_URL = "http://localhost:8080/fake/services/BigFake?wsdl" > s = SOAP::WSDLDriverFactory.new(WSDL_URL).createDriver > x = "abc" > p s.fakeMethod(x) > > Why the latter works, but the former, even passing a String, doesn't > work? Can anybody shed some light on this? > > TIA > Check out this URL http://books.xmlschemata.org/relaxng/ch17-77011.html In particular check out this Restrictions RFC 2045 is defined as transfering binary contents over text-based mail systems. It imposes a line break at least every 76 characters to avoid the inclusion of arbitrary line breaks by the mail systems. Sending base64 content without line breaks is nevertheless a common usage for applications such as SOAP and the W3C XML Schema Working Group. After a request from other W3C Working Groups, the W3C XML Schema Working Group decided to remove the obligation to include these line breaks from the constraints on the lexical space. (This decision was made after the publication of the W3C XML Schema Recommendation. It is now noted in the errata.) When you use the base64 library, line breaks are automatically inserted. irb(main):003:0> Base64.encode64("abc") => "YWJj\n" Try removing the line breaks and see if that helps. irb(main):004:0> Base64.encode64("abc").gsub!(/\n/,"") => "YWJj" Ernie