LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2009, 03:15 PM   #1
beagle804
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Rep: Reputation: 0
Help forming a SOAP client call with PHP


Hello all. Admittedly I an quite new to the world of SOAP. I've got the basics covered and am able to communicate with the Soap Server that my client has provided. But I'm having some trouble forming data into the required arrays so that the request shows up in proper format at the server.

Code:
<PostAssessment xmlns="http://www.server.com">
  <ProjectKey>ABCDE</ProjectKey>
  <UserName>JohnDoe</UserName>
  <Password>JDPassword</Password>
  <AssessmentOrderRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <ClientId idOwner="DDI" xmlns="http://ns.hr-xml.org/2006-02-28">
      <IdValue name="Company">9876</IdValue>
      <IdValue name="Location">54321</IdValue>
      <IdValue name="Client Key">A-Client-Key</IdValue>
    </ClientId>
    <ClientOrderId idOwner="DDI" xmlns="http://ns.hr-xml.org/2006-02-28">
      <IdValue name="Client Order Number">Name-of-the-order</IdValue>
    </ClientOrderId>
  </AssessmentOrderRequest>
</PostAssessment>
The following snippet shows what I have so far...
Code:
$ClientId['IdValue'] = array( 'name' => 'Company' );

$Request['ClientId'] = $ClientId;

$param=array(
'ProjectKey' => 'ABCDE',
'UserName' => 'JohnDoe',
'Password' => 'JDPassword',
'AssessmentOrderRequest' => $Request );

$result = $client->PostAssessment( $param );
When checking the __getLastRequest(), everything looks good up to that point. I just can't get the value "9876" assigned to <IdValue name="company">. Everything I've tried gets a response from the server like this:
Code:
<IdValue name="Company"/>
instead of this:
Code:
<IdValue name="Company">9876</IdValue>
If anyone can help point me in the right direction, I would greatly appreciate it.

Thanks.
 
Old 03-20-2009, 11:04 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Just to make sure we're all on the same page,

1. You're probably using the SOAP extension with PHP 5, and you're probably creating your client object something like this:
http://www.herongyang.com/php/php_soap.html
Code:
<?php # GetTemp.php
# Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
#
   $client = new SoapClient
      ("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl");
2. If so, PHP will automagically read the .wsdl, and your client object can read the SOAP data with "get" methods like this:
Code:
echo("\nReturning value of getTemp() call: ".
      $client->getTemp());
3. Your client's "getTemp()" call will have generated a SOAP request to the server, and the SOAP response will look something like this:[quote]
Quote:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getTempResponse xmlns:ns1="urn:xmethods-Temperature-Demo"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:float">52.0</return>
</ns1:getTempResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The result you'll see in the browser will look something like this:
Quote:
Returning value of getTemp() call: 52
4. Now:
Q: How do you set a SOAP value?
A: Easy. You make a method call from your client object to the server (just like above). Only you pass one or more parameters in your argument:
Code:
echo("\nReturning value of getTemp() call: ".
      $client->getTemp("123456"));
In other words:
1. The WSDL defines the "protocol" - describing the *methods* client and server will use to exchange data, and the data these methods will exchange

2. The PHP SOAP extension "wraps" the WSDL-specific protocol for you, permitting you to read (and, implicitly, write) data to and from the server with the appropriate method calls.

I hope that helps (at least a little bit).

IMHO .. PSM
 
Old 03-20-2009, 12:42 PM   #3
beagle804
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by paulsm4 View Post
Hi -

Just to make sure we're all on the same page,

1. You're probably using the SOAP extension with PHP 5,
Yes, I am using the SOAP extension within PHP 5. I have got my script working to the point that it grabs the WSDL properly. My client has defined a complex XML of which I only posted a portion of it. Once I can get past this part, I can then apply my new knowledge to the rest of the XML. What I've done so far, goes beyond any of the examples you've referenced.

Thanks for the input.....
 
Old 03-20-2009, 01:41 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
In your original post, I wasn't clear if you were asking how to set a value (A: use the methods your WSDL provides), or if you simply weren't seeing the values you expected to see (A: what you see should be what's defined by the WSDL).

Either way: the answer starts with the WSDL (you can't access something with PHP that isn't there in the SOAP response; you can't force something into SOAP that isn't expected by the WSDL).

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP SOAP server returns array using NuSOAP Library mohtasham1983 Programming 2 11-18-2007 10:27 PM
call a php file petenyce Linux - Newbie 3 11-23-2005 04:21 AM
advx php soap support? schallig Mandriva 1 07-15-2005 02:15 AM
Call a shell script from php? jharper101 Programming 2 02-15-2005 01:51 AM
call php scripts djgerbavore Programming 3 11-30-2004 08:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration