EllisLab text mark
Advanced Search
     
Please help to make SOAP call using nusoap
Posted: 30 July 2009 06:00 AM
Joined: 2008-04-26
161 posts

Hi, Endly I have managed to install nusoap


I need to make a SOAP call

POST /1.0/commerce.asmx HTTP/1.1
Host
api.acme.lt
Content
-Typetext/xmlcharset=utf-8
Content
-Lengthlength
SOAPAction
"http://schemas.acme.eu/GetProductSpecification"
<?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:Header>
<
LicenseHeader >
<
LicenseKey>498ec72c-e8e7-48f2-b300-d95666aeb141</LicenseKey>
</
LicenseHeader>
</
soap:Header>
<
soap:Body>
<
GetProductSpecification >
<
GetProductSpecificationRequest>
<
Filters>
<
Filter>
<
Name>Language</Name>
<
Value>en-us</Value>
</
Filter>
<
Filter>
<
Name>SupplierCode</Name>
Acme API Specification v 1.0
24
<Value>018704</Value>
</
Filter>
</
Filters>
</
GetProductSpecificationRequest>
</
GetProductSpecification>
</
soap:Body>
</
soap:Envelope


Which will give me

HTTP/1.1 200 OK
Content
-Typetext/xmlcharset=utf-8
Content
-Lengthlength
<?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>
<
GetProductSpecificationResponse >
<
GetProductSpecificationResult>
<
ProductSpecification>
<
SupplierCode>018704</SupplierCode>
<
ProductProperty>
<
PropertyCode>95</PropertyCode>
<
PropertyName>Video</PropertyName>
<
PropertyValue>nVidia Ge Force 8400M G 256MB</PropertyValue>
</
ProductProperty>
<
ProductProperty>
<
PropertyCode>13</PropertyCode>
<
PropertyName>Type</PropertyName>
<
PropertyValue>13.3 WXGA glare wide</PropertyValue>
</
ProductProperty>
<
ProductProperty>
<
PropertyCode>110</PropertyCode>
<
PropertyName>Keyboard</PropertyName>
<
PropertyValue>US</PropertyValue>
</
ProductProperty>
<
ProductProperty>
<
PropertyCode>64</PropertyCode>
<
PropertyName>Optical storage</PropertyName>
<
PropertyValue>Super Multi DL DVD+/-RW (CBB standard)</PropertyValue>
</
ProductProperty>
<
ProductProperty>
<
PropertyCode>101</PropertyCode>
<
PropertyName>AC adapter</PropertyName>
<
PropertyValue>Output 19V DC 3.42A 90WInput 100~240V AC 50/60Hz universal (CBB
standard
)</PropertyValue>
</
ProductProperty>
<
ProductProperty>
<
PropertyCode>96</PropertyCode>
<
PropertyName>HDD</PropertyName>
<
PropertyValue>SATA 120GB 5400rpm (CBB standard)</PropertyValue>
</
ProductProperty>
</
ProductSpecification>
Acme API Specification v 1.0
25
</GetProductSpecificationResult>
</
GetProductSpecificationResponse>
</
soap:Body>
</
soap:Envelope

 

in my controller i have made usual code from forum I have got example

$this->load->library("nusoap");

                 
$data['mod_content']='';







                       
$this->soapclient = new nusoap_client('https://api.acme.lt/1.0/commerce.asmx?WSDL');
                                 
$this->soapclient->setHeaders('
<LicenseHeader >
<LicenseKey>498ec72c-e8e7-48f2-b300-d95666aeb141</LicenseKey>
</LicenseHeader>



'
);



              
$params=array('Language'=>'en-us','UpdateSince'=>'');



        if(!
$this->soapclient->fault)
        
{
            
if(!$this->soapclient->getError())
            
{
                $member 
$this->soapclient->call(
                    
'getVendorList'// <- just when we get here the function becomes visible and can be called
                     
array('parameters' => $param), ''''falsetrue
                
);

                
print_r($member); // see what is coming out of the WS
            
}
        }
        else{

        $data[
'mod_content'].="<h1>Error</h1>";
        

 

but i get

 

Array
(
    
[faultcode] => soap:Client
    [faultstring] 
=> Server did not recognize the value of HTTP Header SOAPAction: .
    
[detail] => 

 


How to fix this error and how to parse the response.
Please help!!!!

 
Posted: 30 July 2009 08:58 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

any help pleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaseeeeeeeeeeeeee…

 
Posted: 30 July 2009 01:02 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-11
967 posts

Not sure how this is a CI issue. Why not try going over to the NuSOAP forums?

http://sourceforge.net/forum/forum.php?forum_id=193579

 Signature 

Google Analytics HOWTO | Enable GET | Netbeans PHP Integration

 
Posted: 31 July 2009 01:12 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2007-08-29
21 posts

Well, I’m not an expert in this SOAP-thing but I try to be of some help.

Here are two solutions, I already tried them myself for the webservice you gave.

1. If you use PHP’s internal soap functions (see http://www.php.net/soap):

class LicenseHeader{
    
public $LicenseKey '';
}

$client 
= new SoapClient('https://api.acme.lt/1.0/commerce.asmx?WSDL', array('trace'=> 1'exceptions'=>0));

$license_header = new LicenseHeader();
$license_header->LicenseKey '498ec72c-e8e7-48f2-b300-d95666aeb141';

$params = array('Language'=>'en-us','UpdateSince'=>'');

$member $client->__soapCall(
    
'GetVendorList',
     
$params,
     
null,
     new 
SoapHeader(
        
'http://schemas.acme.eu/',                                      
        
'LicenseHeader'
        
$license_header
    
)
);

print_r($member); 

2. If you use nusoap (I made this test with nusoap v1.2):

//you need to put the second parameter set to true because it needs to know this is a wsdl file, otherwise it won't work

$client = new soapclient('https://api.acme.lt/1.0/commerce.asmx?WSDL'true);

//here is a bug in forum you need to spell xmlns="http://schemas.acme.eu/" I see it disappears if put inside a tag.
//if you don't clearly specify this namespace it won't work 

$client->setHeaders('<LicenseHeader xml ns="http://schemas.acme.eu/"><LicenseKey>498ec72c-e8e7-48f2-b300-d95666aeb141</LicenseKey></LicenseHeader>');

$params=array('Language'=>'en-us','UpdateSince'=>'');

$member $client->call(
                    
'GetVendorList',
                    
$params
                
);

print_r($member); 

and the answer is right back what you need, the list of vendors.

Be careful, if you work in a safe-moded environment, put the condition below in the nusoap library, before the curl’s option CURL_FOLLOWLOCATION, so you won’t get a warning:

if ((!ini_get("safe_mode")) && (!strlen(ini_get("open_basedir")))) curl_setopt($this->chCURLOPT_FOLLOWLOCATION1); 

Good luck!

 
Posted: 31 July 2009 02:29 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

Fatal error: Class declarations may not be nested in Z:\home\smysite.com\www\system\application\controllers\soap_parcer.php on line 31

31 line is

class LicenseHeader{
    
public $LicenseKey '';


and second code gives

A PHP Error was encountered

Severity: Warning

Message: SoapClient::SoapClient() expects parameter 2 to be array, boolean given

Filename: controllers/soap_parcer.php

Line Number: 34

Fatal error: Uncaught SoapFault exception: [Client] SoapClient::SoapClient() [function.SoapClient-SoapClient]: Invalid parameters in Z:\home\mysite.com\www\system\application\controllers\soap_parcer.php:34 Stack trace: #0 Z:\home\mysite.com\www\system\application\controllers\soap_parcer.php(34): SoapClient->SoapClient(‘https://api.acm…’, true) #1 [internal function]: Soap_parcer->index() #2 Z:\home\mysite.com\www\system\codeigniter\CodeIgniter.php(224): call_user_func_array(Array, Array) #3 Z:\home\mysite.com\www\index.php(115): require_once(‘Z:\home\spamr.c…’) #4 {main} thrown in Z:\home\mysite.com\www\system\application\controllers\soap_parcer.php on line 34

 
Posted: 31 July 2009 02:47 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

Maybe I am wrong in installing NUSOAP? i have just put the file from wiki in /system/application/libraries, then downloaded the latest version of nusoap from Sourceforge, and them also put all files from /lib/ folder to the same folder as nusoap.php from wiki ..

when I uncomment this part

/* load classes*/

// necessary classes
//require_once('class.soapclient.php');
//require_once('class.soap_val.php');
//require_once('class.soap_parser.php');
//require_once('class.soap_fault.php');

// transport classes
//require_once('class.soap_transport_http.php');

// optional add-on classes
//require_once('class.xmlschema.php');
//require_once('class.wsdl.php');

// server class
//require_once('class.soap_server.php'); 

I get

Fatal error: Class ‘nusoap_base’ not found in Z:\home\mysite.com\www\system\application\libraries\class.soapclient.php on line 26

What to do , I don’t know…

 
Posted: 31 July 2009 04:14 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2007-08-29
21 posts

Obviously, first of all you need to create a file for the LicenseHeader class and then load it into your controller.

Second, I don’t think the nusoap library from Sourceforge is the latest, I’ve got v1.2 and they have v0.7.3. But you may just get lucky, give it a try.

Third, you have to load the nusoap.php file from their kit, which is the file that includes all the other classes in itself.

Be careful, if you have the latest PHP version installed there may be some conflicts in function names because PHP has classes and functions are named alike. In this case just prefix your classes from nusoap.php with “nu”: e.g. class “soapclient” becames class “nusoapclient” etc.

 
Posted: 31 July 2009 04:29 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

can you email me version 1.2 ? thanks….

 
Posted: 01 August 2009 05:14 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

I understood everything(THANKS TO LEO!!!)

Just one thing is not clear in NuSoap and Soap ...


For example there is a 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:Header>
<
LicenseHeader >
<
LicenseKey>498ec72c-e8e7-48f2-b300-d95666aeb141</LicenseKey>
</
LicenseHeader>
</
soap:Header>
<
soap:Body>
<
GetProductList >
<
GetProductListRequest>
<
Filters>
<
Filter>
<
Name>Language</Name>
<
Value>lt-lt</Value>
</
Filter>
<
Filter>
<
Name>Currency</Name>
<
Value>LTL</Value>
</
Filter>
</
Filters>
</
GetProductListRequest>
</
GetProductList>
</
soap:Body>
</
soap:Envelope

 

 

How to pass

<Filters>
<
Filter>
<
Name>Language</Name>
<
Value>lt-lt</Value>
</
Filter>
<
Filter>
<
Name>Currency</Name>
<
Value>LTL</Value>
</
Filter>
</
Filters


My head is blowing….

 
Posted: 09 August 2009 05:41 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2007-08-29
21 posts

For this method of the webservice you need to use a serialized envelope in order to send the parameters, like this:

$client = new nusoapclient('https://api.acme.lt/1.0/commerce.asmx?WSDL'true);

$params $client->serializeEnvelope('
  <GetProductList xml ns="http://schemas.acme.eu/">
      <GetProductListRequest>
     <Filters>
       <Filter>
        <Name>Language</Name>
        <Value>lt-lt</Value>
       </Filter>
       <Filter>
        <Name>Currency</Name>
        <Value>LTL</Value>
       </Filter>
      </Filters>
       </GetProductListRequest>
    </GetProductList>'
,'
    <LicenseHeader >
      <LicenseKey>498ec72c-e8e7-48f2-b300-d95666aeb141</LicenseKey>
    </LicenseHeader>'
,array(),'document''literal');

$member $client->send($params'http://schemas.acme.eu/GetProductList'); 

Notice that in this case the LicenseHeader is sent with this serialized envelope in the third parameter (header), and the filters in the second parameter (body) of the function serializeEnvelope (see the nusoap documentation), as you can see in the method definition:

<soap:Header>
    <
LicenseHeader xml ns="http://schemas.acme.eu/">
      <
LicenseKey>string</LicenseKey>
    </
LicenseHeader>
  </
soap:Header>
  <
soap:Body>
    <
GetProductList xml ns="http://schemas.acme.eu/">
      <
GetProductListRequest>
        <
Filters>
          <
Filter>
            <
Name>string</Name>
            <
Value>string</Value>
          </
Filter>
          <
Filter>
            <
Name>string</Name>
            <
Value>string</Value>
          </
Filter>
        </
Filters>
      </
GetProductListRequest>
    </
GetProductList>
  </
soap:Body

The other parameters: ‘document’ and ‘literal’ are specified in the wsdl of the webservice (see style=‘document’ and use=‘literal’ below):

<wsdl:operation name="GetProductList">
<
soap:operation soapAction="http://schemas.acme.eu/GetProductList" style="document"/>
<
wsdl:input>
<
soap:body use="literal"/>
<
soap:header message="tns:GetProductListLicenseHeader" part="LicenseHeader" use="literal"/>
</
wsdl:input>
<
wsdl:output>
<
soap:body use="literal"/>
</
wsdl:output>
</
wsdl:operation

Be careful, you may need to adjust the connection timeout or the response timeout respectively, to be sure that the response is not very big (in the matter of data) or your connection is not chunked in some way, in order to prevent the script stop running before the list is downloaded.

 
Posted: 09 August 2009 05:48 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2008-04-26
161 posts

Hi Leo,
you are soooooooooooo kind,thanks a lot!!!!!

I have solved problem like this

$arik='
<GetProductListRequest>
<Filters>
<Filter>
<Name>Language</Name>
<Value>lt-lt</Value>
</Filter>
<Filter>
<Name>Currency</Name>
<Value>LTL</Value>
</Filter>
</Filters>
</GetProductListRequest>
'
;





              
$this->load->library('SimpleXml');




                
$my_data $this->simplexml->xml_parse($arik);



              
//print_r($my_data);




             
$params=array('GetProductListRequest' =>array('filters'=>array(array('Name'=>'Language','Value'=>'lt-lt'),array('Name'=>'Currency','Value'=>'LTL'))));

            
$params=array(array('GetProductListRequest'=>$my_data)) ;


               
$req=array($params);



// print_r($req);

             
$member $client->call(
                    
'GetProductList',
                    
$params
                
); 


will try your code tomorrow and will give feedback smile))) Anyway you are soooooooooooooooooooo kind 10x a looooot