Soap4r. I just dont get it

Hi.

I have tried for a hours but I still cannot get it. What is wrong with
my codes? I keep getting this error
#<SOAP:Mapping::Object:0x2bb0e90>: Fault occurred -->
System.Xml.XmlElement (SOAP::FaultError)

Below is my code to access the webservice. According to the logs from
the webservice server, I am able to access to the webservice. But there
seems to be something wrong in the way I place my input argument.

···

#######
require 'soap/rpc/driver'

Host = "http://mysite/serviceA/serviceA1.asmx"
NS = "urn:mysite.co.uk:webservices"
client = SOAP::RPC::Driver.new(Host, NS)
client.add_method_with_soapaction('mygetData', 'getData', 'dataID')
p client.mygetData(1)
#######

And this is the webservice statements from the server. It says this is
how I should form my soap request.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <getData xmlns="urn:mysite.co.uk:webservices">
       <DataID>int</DataID>
       <inputstring>
         <string>string</string>
       </inputstring>
     </getData>
   </soap:Body>
</soap:Envelope>

Hi,

I have tried for a hours but I still cannot get it. What is wrong with
my codes? I keep getting this error
#<SOAP:Mapping::Object:0x2bb0e90>: Fault occurred -->
System.Xml.XmlElement (SOAP::FaultError)

Do you have the WSDL for the service you want to connect with?

If you don't... try below.

Below is my code to access the webservice. According to the logs from
the webservice server, I am able to access to the webservice. But there
seems to be something wrong in the way I place my input argument.

#######
require 'soap/rpc/driver'

Host = "http://mysite/serviceA/serviceA1.asmx&quot;
NS = "urn:mysite.co.uk:webservices"
client = SOAP::RPC::Driver.new(Host, NS)
client.add_method_with_soapaction('mygetData', 'getData', 'dataID')

client.add_method_with_soapaction('getData',
"soapactionthattheserverrequires", 'DataID', "inputstring")
client.generate_explicit_type = false

p client.mygetData(1)

p client.getData(5, ["string1", "string2"])

It should send a request as follows:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:env="Error;
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  <env:Body>
    <n1:getData xmlns:n1="foo">
      <DataID>5</DataID>
      <inputstring>
        <item>string1</item> <== XXX
        <item>string2</item> <== XXX
      </inputstring>
    </n1:getData>
  </env:Body>
</env:Envelope>

The server may not accept the request because of the element name at
XXX part above does not match with expected one (<string>). Then you
need WSDL.

Regards,
// NaHi

···

On Wed, 22 Sep 2004 14:35:50 +0900, nkb <nkb@pacific.net.sg> wrote:

What is the Fault that the server is giving you? You should be able
to access the SOAP:faultstring or SOAP:detail. Since it is an ASP.NET
Web Service, you should go into the web.config file and turn off
custom errors. This way ASP.NET will return the callstack that it
generated on the error. Then you can see what the exact error is. My
guess is that you are missing parameters or accessing elements that
really aren't there (maybe a string array and you are getting an index
out of bounds exception).

The ASP.NET Web Services engine is very liberal in what it accepts.
It won't error if you send it info that it doesn't understand and it
won't error if you DON'T send it info that is required.

The server may not accept the request because of the element name at
XXX part above does not match with expected one (<string>). Then you
need WSDL.

It will accept the request. But it will ignore what it doesn't understand.

You can get the WSDL by adding the query string ?WSDL. Hopefully
soap4r will understand the WSDL spit out :slight_smile: I've stopped using
ASP.NET auto generated WSDL. I find it easier to write it by hand.

···

--
Justin Rudd
http://seagecko.org/thoughts/

Thanks for the prompt reply.

client.generate_explicit_type statement generate an error
undefined method 'generate_explicit_type=' for #<SOAP::RPC::Driver:0x2830c08> (NoMethodError)

So I commented it out but still receives the same error
#<SOAP::Mapping::Object:0x2ba5268>: Fault occurred --> System.Xml.XmlElement (SOAP::FaultError)

I wonder if I should just skip the soap4r and simply use ruby to do a simple http post with my own soap content? Would this be not adviable?
Many thanks!!

···

client.add_method_with_soapaction('getData',
"soapactionthattheserverrequires", 'DataID', "inputstring")
client.generate_explicit_type = false

p client.getData(5, ["string1", "string2"])

It should send a request as follows:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:env="Error;
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
  <env:Body>
    <n1:getData xmlns:n1="foo">
      <DataID>5</DataID>
      <inputstring>
        <item>string1</item> <== XXX
        <item>string2</item> <== XXX
      </inputstring>
    </n1:getData>
  </env:Body>
</env:Envelope>

The server may not accept the request because of the element name at
XXX part above does not match with expected one (<string>). Then you
need WSDL.

Regards,
// NaHi

I might asd well start writing english SOAP
documentation that explains details of soap4r. Where
should I start? I know I should definitely document
where I was having trouble at first.

you are at gmail now, why?

-dross

Hi,

> I have tried for a hours but I still cannot get
it. What is wrong with
> my codes? I keep getting this error
> #<SOAP:Mapping::Object:0x2bb0e90>: Fault occurred
-->
> System.Xml.XmlElement (SOAP::FaultError)

Do you have the WSDL for the service you want to
connect with?

If you don't... try below.

> Below is my code to access the webservice.
According to the logs from
> the webservice server, I am able to access to the
webservice. But there
> seems to be something wrong in the way I place my
input argument.
>
> #######
> require 'soap/rpc/driver'
>
> Host = "http://mysite/serviceA/serviceA1.asmx&quot;
> NS = "urn:mysite.co.uk:webservices"
> client = SOAP::RPC::Driver.new(Host, NS)
> client.add_method_with_soapaction('mygetData',
'getData', 'dataID')

client.add_method_with_soapaction('getData',
"soapactionthattheserverrequires", 'DataID',
"inputstring")
client.generate_explicit_type = false

> p client.mygetData(1)

p client.getData(5, ["string1", "string2"])

It should send a request as follows:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope

xmlns:env="Error;

   

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;&gt;

···

--- "NAKAMURA, Hiroshi" <nakahiro@gmail.com> wrote:

On Wed, 22 Sep 2004 14:35:50 +0900, nkb > <nkb@pacific.net.sg> wrote:
  <env:Body>
    <n1:getData xmlns:n1="foo">
      <DataID>5</DataID>
      <inputstring>
        <item>string1</item> <== XXX
        <item>string2</item> <== XXX
      </inputstring>
    </n1:getData>
  </env:Body>
</env:Envelope>

The server may not accept the request because of the
element name at
XXX part above does not match with expected one
(<string>). Then you
need WSDL.

Regards,
// NaHi

_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

ya. I did check the server error. It says Data Does not exist. Which I suppose means I'm sending some wrong arguments over. There is a switch case in the .net codes and in the switch case, it default to such error when the input arugment is not correct.
By the way, why do I need WSDL? What does it mean that I need WSDL? I thought all web services would have some form of WSDL isnt it? Anyway, I can read the WSDL from the internet explorer. Is that enough?

···

Justin Rudd wrote on 2004/09/22 15:37: > What is the Fault that the server is giving you? You should be able > to access the SOAP:faultstring or SOAP:detail. Since it is an ASP.NET

Web Service, you should go into the web.config file and turn off
custom errors. This way ASP.NET will return the callstack that it
generated on the error. Then you can see what the exact error is. My
guess is that you are missing parameters or accessing elements that
really aren't there (maybe a string array and you are getting an index
out of bounds exception).

The ASP.NET Web Services engine is very liberal in what it accepts. It won't error if you send it info that it doesn't understand and it
won't error if you DON'T send it info that is required.

The server may not accept the request because of the element name at
XXX part above does not match with expected one (<string>). Then you
need WSDL.

It will accept the request. But it will ignore what it doesn't understand.

You can get the WSDL by adding the query string ?WSDL. Hopefully
soap4r will understand the WSDL spit out :slight_smile: I've stopped using
ASP.NET auto generated WSDL. I find it easier to write it by hand.

Personally, I was unable to get any Ruby SOAP client to work until our
ASP.NET web service was switched to use RPC encoding. After that, I was
able to use the auto-generated WSDL, and the service worked perfectly.

That being said, after trying to hack the SOAP4R library to allow
dynamic configuration of proxy settings, I just gave up, and am now
using basic HTTP GET, and passing my (all string-valued) parameters as
the query string.

Just out of curiosity, are you still calling the service with only one
argument, as in your first example? Have you tried adding an array of
strings to the parameters, to see if the error is actually coming from
that?

···

--
Lennon
rcoder.net

Hi,

Thank you for great advice about ASP.NET! It much help me to answer
ASP.NET related questions I'll receive.

> The server may not accept the request because of the element name at
> XXX part above does not match with expected one (<string>). Then you
> need WSDL.

It will accept the request. But it will ignore what it doesn't understand.

Gee.

You can get the WSDL by adding the query string ?WSDL. Hopefully
soap4r will understand the WSDL spit out :slight_smile: I've stopped using
ASP.NET auto generated WSDL. I find it easier to write it by hand.

Recent soap4r should understand ASP.NET auto generated WSDL file but I
agree with you that generally it is easy to write by hand.

Regards,
// NaHi

···

On Wed, 22 Sep 2004 15:37:00 +0900, Justin Rudd <justin.rudd@gmail.com> wrote:

Hi,

client.generate_explicit_type statement generate an error
undefined method 'generate_explicit_type=' for
#<SOAP::RPC::Driver:0x2830c08> (NoMethodError)

Doh. This API (generate_explicit_type=) is recently added. Can you
try the latest soap4r tarball at http://rrr.jin.gr.jp/download/ ?

Or, please try
  client.default_encodingstyle =
SOAP::EncodingStyle::ASPDotNetHandler::Namespace
instead of
  client.generate_explicit_type = false

Regards,
// NaHi

···

On Wed, 22 Sep 2004 15:40:01 +0900, nkb <nkb@pacific.net.sg> wrote:

Hi,

I might asd well start writing english SOAP
documentation that explains details of soap4r. Where
should I start? I know I should definitely document
where I was having trouble at first.

Speaking about myself, I don't very often read documents... Generally
I first read sample programs, google sample programs, then write a
sample by myself. The next step is tracing its source code through
debugger. I don't think no documents required, but I cannot imagine
what documents are requied. Maybe do to lack of my English skill.

Soap4r users, how do you think?

you are at gmail now, why?

It has nothing to do about soap4r. I'm just tired of collecting spams
to my job e-mail address (I'm an admin). Gmail filters spams without
my computer/network resource!

Regards,
// NaHi

···

On Wed, 22 Sep 2004 21:24:53 +0900, David Ross <drossruby@yahoo.com> wrote:

By the way, why do I need WSDL? What does it mean that I need WSDL? I
thought all web services would have some form of WSDL isnt it? Anyway, I
can read the WSDL from the internet explorer. Is that enough?

Without going into a lot of detail, the WSDL is the contract. It
describes services (objects) and ports (methods). The ports are what
you send across the wire.

Given the WSDL, you can feed it into WSDL4R (or maybe even at runtime)
and get Ruby code that will "do the right thing" on the wire including
element names. My guess is your ASMX file (or the code-behind) has a
method like so (can't infer the return type from what you posted) -

GetData(int DataID, string inputstring)

If you are validating that there are elements in inputstring, the way
you are sending them (and the first answer you received) won't work
because you need to pass in the array of items. And ASP.NET is very
specific in what it is looking for. It will be looking for the
fragment -

<inputstring>
   <string>foo</string>
   <string>bar</string>
</inputstring>

Anything else will be ignored, but it won't raise an error. Also XML
is case sensitive, make sure the element names going from Ruby to
ASP.NET are spelled correctly including case. I know I've made that
mistake many, many times.

I can't really comment much more because I've not worked with SOAP4R.
I can answer whatever issues you have with ASP.NET though. I've
learned over the years to bend it to my will :slight_smile:

···

--
Justin Rudd
http://seagecko.org/thoughts/

I am giving up on the soap4r for now. I think it is a great library to use if I get to have it working (and if there maybe more examples for the uninitiated like me). But I'm on negative time now, and http happens to work for me meanwhile. :slight_smile:

···

rcoder@gmail.com wrote on 2004/09/23 1:24:

Personally, I was unable to get any Ruby SOAP client to work until our
ASP.NET web service was switched to use RPC encoding. After that, I was
able to use the auto-generated WSDL, and the service worked perfectly.

That being said, after trying to hack the SOAP4R library to allow
dynamic configuration of proxy settings, I just gave up, and am now
using basic HTTP GET, and passing my (all string-valued) parameters as
the query string.

Just out of curiosity, are you still calling the service with only one
argument, as in your first example? Have you tried adding an array of
strings to the parameters, to see if the error is actually coming from
that?

--
Lennon
rcoder.net

Hi,

Personally, I was unable to get any Ruby SOAP client to work until our
ASP.NET web service was switched to use RPC encoding. After that, I was
able to use the auto-generated WSDL, and the service worked perfectly.

For my testing purpose, can I see the WSDL which is not RPC encoding
you failed to use? Ignore this if you think it cannot be. Some WSDL
should be private because of business contract.

That being said, after trying to hack the SOAP4R library to allow
dynamic configuration of proxy settings, I just gave up, and am now
using basic HTTP GET, and passing my (all string-valued) parameters as
the query string.

Would you please explain what "dynamic configuration of proxy setting"
is? Sounds that it should be supported.

Regards,
// NaHi

···

On Thu, 23 Sep 2004 01:24:34 +0900, rcoder@gmail.com <rcoder@gmail.com> wrote:

Hi,

> I might asd well start writing english SOAP
> documentation that explains details of soap4r.
Where
> should I start? I know I should definitely
document
> where I was having trouble at first.

Speaking about myself, I don't very often read
documents... Generally
I first read sample programs, google sample
programs, then write a
sample by myself. The next step is tracing its
source code through
debugger. I don't think no documents required, but
I cannot imagine
what documents are requied. Maybe do to lack of my
English skill.

Well what I am going to write will make it easy for
people to quickly look at it, and look at examples on
the documentation. A quick-ref source as well. I
notice ruby lacks a site like it so I will launch
documentation with my CMS(once it is finished).

Soap4r users, how do you think?

> you are at gmail now, why?

It has nothing to do about soap4r. I'm just tired
of collecting spams
to my job e-mail address (I'm an admin). Gmail
filters spams without
my computer/network resource!

Good point. Filtering all those 409 scams are painful,
and takes a great amount of resource if you have many
users. Its a pain to deal with them.

--dross

···

--- "NAKAMURA, Hiroshi" <nakahiro@gmail.com> wrote:

On Wed, 22 Sep 2004 21:24:53 +0900, David Ross > <drossruby@yahoo.com> wrote:

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

Hi,

···

On Thu, 23 Sep 2004 01:29:14 +0900, nkb <nkb@pacific.net.sg> wrote:

I am giving up on the soap4r for now. I think it is a great library to
use if I get to have it working (and if there maybe more examples for
the uninitiated like me). But I'm on negative time now, and http happens
to work for me meanwhile. :slight_smile:

Doh, I should have read this first! Ignore previous mail I asked to try.

Sorry for wasting your time about soap4r. Indeed, soap4r should have
good documents.

Regards,
// NaHi