Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML + SOAP I need help

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello peeps,

I've looked at the SOAP documentation and I cannot understand it.

I need to make a soap request with an XML file and capture the returned data and process it. it's for an auto-login system to integrate with a product provider.

They have sent me an example XML file and some Visual Studio VB code, but I use perl and so it means nothing to me.

Can anyone help?

here is the XML template.

Code:
<soap:envelope xmlns:soap="urn:schemas-xmlsoap-org:soap.v1">

            <soap:header xmlns:matrix="[URL unfurl="true"]http://myurl"[/URL] soap:encodingStyle="[URL unfurl="true"]http://www.w3.org/2001/12/soap-encoding">[/URL]

            <matrix:system>

                <username>myid</username>

                <password>mypassword</password>

            </matrix:system>

        </soap:header>

 

        <soap:body xmlns:soap='[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/'[/URL] soap:encodingStyle="[URL unfurl="true"]http://www.w3.org/2001/12/soap-encoding">[/URL]

            <query>

              <url>/</url>

            </query>

        </soap:body>

</soap:envelope>
ok so I can make a variable equal the required data, but i'm stumped at how I make a SOAP request.

I've been told I need to send that data to a specific URL and call their ‘logintoken01’ method, I will then get returned either an error or an XML file which I will then need to parse.

I understand the principle of all this , just need help with syntax, so appreciate everyones input.

so far I have..
Code:
use SOAP::Lite;

print SOAP::Lite
    -> uri('[URL unfurl="true"]http://www.url_i_need_to_call.com')[/URL]
    -> logintoken01()
    -> result;

now this is based on reading the CPAN documentation, i'm asuming I need to change the
Code:
print SOAP::Lite
to
Code:
my $returned_xml = new SOAP::Lite;
$returned_xml-> uri('[URL unfurl="true"]http://www.url_i_need_to_call.com');[/URL]
$returned_xml-> logintoken01();
$returned_xml-> result;
or is this wrong?

and I don't understand how I pass in the rerquired XML data.

do I put that between the brackets of the method call? so I could do
Code:
my $xml = "my xml data";
my $returned_xml = new SOAP::Lite;
$returned_xml-> uri('[URL unfurl="true"]http://www.url_i_need_to_call.com');[/URL]
$returned_xml-> logintoken01($xml);
$returned_xml-> result;

all help understanding what i'm doing is appreciated.

regards, 1DMF.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Try going to the URL of the web service in your browser. Some services will give you a help page, which might give you a pointer. I used this a couple of years ago at a client site (so no code sample, I'm afraid), but from memory the proxy was important (apologies for vagueness)...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
From
The uri() identifies the class to the server, and the proxy() identifies the location of the server itself.

proxy()

proxy() is simply the address of the server to contact that provides the methods. You can use http:, mailto:, even ftp: URLs here.

uri()

Each server can offer many different services through the one proxy() URL. Each service has a unique URI-like identifier, which you specify to SOAP::Lite through the uri() method. If you get caught up in the gripping saga of the SOAP documentation, the "namespace" corresponds to the uri() method.

---------------------
So,
Code:
my $xml = 'Your XML data';
use SOAP::Lite;
my $client = SOAP::Lite->new();
$client->uri( 'URI of the module' );
$client->proxy( 'URL of the script/service' );
my $som = $client->logintoken01( $xml );
my $output = $som->result;
 
I can't get it to work , I just keep getting this error
Code:
<soap:Body soap:encodingStyle="[URL unfurl="true"]http://www.w3.org/2001/12/soap-encoding">[/URL]

      <soap:Fault>

        <faultcode>soap:Client</faultcode>

        <faultstring>1 - Unable to find soap header node</faultstring>

        <detail></detail>

      </soap:Fault>

    </soap:Body>

</soap:Envelope>

So I gave up with SOAP and am using LWP instead and it works fine....
Code:
my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => '[URL unfurl="true"]https://myurl/my.asp');[/URL]
$request->header(SOAPAction => '"logintoken01"');
$request->content($xml);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

if($response->code == 200) {
    print "Content-Type: text/html\n\n";
    print $response->as_string;
}
else {
    print "Content-Type: text/html\n\n";
    print $response->error_as_HTML;
}

though the returned data doesn't seem to be valid XML, any ideas why this is?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
You mentioned that you had some sample VB code. If there isn't too much of it, can you (gags on own v*mit) post it?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
here is the VB code I got sent...
Code:
1. Create a blank project.

2. Add a web reference with URL of [URL unfurl="true"]https://myURL/content/integrate.wsdl?[/URL]  

3. Past the following code in to where ever you like - form onClick?

 

        ' Declares

        Dim ba As New ba.Integrate

        Dim a As New ba.auth

        Dim lsViewURL As String = ""

 

        ' Provide the UN/PWD

        a.username = "testuid"

        a.password = "testpwd"

 

        ' Set the authentication

        ba.authValue = a

 

        ' Enter the initial URL

        lsViewURL = "/portfolio"

 

        ' Update the URL with a login token

        ba.dologintoken01(lsViewURL)

 

        ' Debug

        Debug.Print(lsViewURL)

 

Load a browser to the URL.
It means nothing to me.

But I got it working with LWP across HTTPS , the issue is the returned XML is corrupt plus I can't seem to find SOAP::parser module on any of my repositories, so how do I parse the returned soap XML>?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top