decibel3276 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to access a webservice and believe I have finally hit the service however it is rejecting my request as there is no namespace set for the QueryAbc method.
#!C:/Perl/bin/perl.exe use warnings; use strict; use XML::Simple; use SOAP::Lite +trace => 'debug'; use Data::Dumper; my $post = "<request>"; $post = $post . "<Number>".$number."</Number>"; $post = $post . "<InternalData></InternalData>"; $post = $post . "</request>"; my $soap = SOAP::Lite -> proxy ('https://myrealm.com/service.asmx') -> service ('file:abc.wsdl'); sub SOAP::Transport::HTTP::Client::get_basic_credentials { return 'username@subrealm.realm.net' => '!pa$$w0rd!'; }; my $elem = SOAP::Data->type('xml' => $post); $soap->QueryAbc($elem);
The resulting XML looks good except for that missing namespace:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/enc +oding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encod +ing/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmln +s:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://w +ww.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <QueryAbc xmlns=""> <request> <Number>9765551212</Number> <InternalData></InternalData> </request> </QueryAbc> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Anyone know how to add the namespace in the <QueryAbc> node?

Replies are listed 'Best First'.
Re: SOAP::Lite Question
by cengineer (Pilgrim) on Jun 05, 2007 at 20:02 UTC
    You can try creating a module from the wsdl using stubmaker.
    stubmaker http://www.service.com/service?wsdl
    From there, you can edit the namespaces for each function within the module.
      That worked beautifully. Now the only thing that appears to be holding up my request is the SOAP-ENV prefix. How would I go about modifying the envelope so that instead of SOAP-ENV, it would just say, for example, soap:Envelope instead of SOAP-ENV:Envelope?
        I was reading through some forums and discovered that, from what I was able to comprehend, that this is because the messages is being encoded in SOAP-RPC and not doc/literal which is what the .NET service is looking for. Is this correct? Can anyone shed some light on this for me?
Re: SOAP::Lite Question
by naikonta (Curate) on Jun 05, 2007 at 16:12 UTC
    I'm not answering your question as I never play with SOAP. I just wanted to let you know that you don't need that multiple assignments and superflous double quotes on literal strings. Instead, you can use <<here-doc syntax:
    my $post = <<EOF; <request> <Number>$number</Number> <InternalData></InternalData> </request> EOF
    But, where the heck that $number variable comes from?

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: SOAP::Lite Question
by Util (Priest) on Jun 05, 2007 at 16:33 UTC

    If I have read this article correctly, with newer SOAP::Lite (>= 0.68), do this:

    $soap->default_ns('http://www.someuri.com');
    and with older SOAP::Lite (<= 0.67), do this:
    $soap->uri('http://www.someuri.com');

      Neither of these suggestions do what I am looking to do. Is there any way to edit the body of a soap request before it is dispatched?
Re: SOAP::Lite Question
by jhourcle (Prior) on Jun 05, 2007 at 19:49 UTC
    Anyone know how to add the namespace in the <QueryAbc> node?

    Yes, Util does.

    However, you'll want to make sure that you call it _after_ your call to service(), so it overrides whatever's in your wsdl. Of course, if it were me, I'd just change the wsdl so it had the namespace in it (and the proxy ... which I'm guessing it has in it, and your call to proxy() is superfluous.

Re: SOAP::Lite Question
by ForgotPasswordAgain (Vicar) on Jun 05, 2007 at 16:18 UTC