• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help to make SOAP call using nusoap

#1
[eluser]Gewa[/eluser]
Hi, Endly I have managed to install nusoap


I need to make a SOAP call

Code:
POST /1.0/commerce.asmx HTTP/1.1
Host: api.acme.lt
Content-Type: text/xml; charset=utf-8
Content-Length: length
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

Code:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
&lt;?xml version="1.0" encoding="utf-8"?&gt;
<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 90W; Input : 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

Code:
$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), '', '', false, true
                );

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

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



but i get



Code:
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!!!!

#2
[eluser]Gewa[/eluser]
any help pleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaseeeeeeeeeeeeee...

#3
[eluser]bretticus[/eluser]
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

#4
[eluser]Leonardo Radoiu[/eluser]
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):

Code:
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):

Code:
//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:

Code:
if ((!ini_get("safe_mode")) && (!strlen(ini_get("open_basedir")))) curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);

Good luck!

#5
[eluser]Gewa[/eluser]
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
Code:
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() [<a href='function.SoapClient-SoapClient'>function.SoapClient-SoapClient</a>]: 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

#6
[eluser]Gewa[/eluser]
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
Code:
/* 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...

#7
[eluser]Leonardo Radoiu[/eluser]
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.

#8
[eluser]Gewa[/eluser]
can you email me version 1.2 ? thanks....

#9
[eluser]Gewa[/eluser]
I understood everything(THANKS TO LEO!!!)

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


For example there is a request


Code:
&lt;?xml version="1.0" encoding="utf-8"?&gt;
<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


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


My head is blowing....

#10
[eluser]Leonardo Radoiu[/eluser]
For this method of the webservice you need to use a serialized envelope in order to send the parameters, like this:

Code:
$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:

Code:
<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):

Code:
<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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.