Developer Forum [ All Topics | New Topic ]

Thread: Problems getting the web service API working with PHP

Hello,

I am trying to access the GetDiamond method using the php code below and I am getting the following error:

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> You are not authenticated. Please run the Login function first.

Although the Login function is run first. As mentioned in a previous thread
http://technet.rapaport.com/Forum/Developer.aspx?TopicID=2541

Can you please advice what is needed to be added to the code below in order to work ? will the
__setSoapHeaders method work and if so what is the correct code to use it ?

Regards,
Ofer

<?php
        $soapClient = new SoapClient("https://technet.rapaport.com/WebServices/RetailFeed/RetailFeed.asmx?wsdl");
   
        // Prepare SoapHeader parameters
        $sh_param = array(
                    'Username'    =>    'Username',
                    'Password'    =>    'Password');
        $headers = new SoapHeader('http://soapserver.example.com/webservices', 'UserCredentials', $sh_param);
   
        // Prepare Soap Client
        $soapClient->__setSoapHeaders(array($headers));
   
        // Setup the RemoteFunction parameters
        $ap_param = array(
                      'Username'    =>    'XXXX',
                      'Password'    =>    'XXXX');
                   
        // Call RemoteFunction ()
        $error = 0;
        try {
            $info = $soapClient->__call("Login", array($ap_param));
            print_r($info);
        } catch (SoapFault $fault) {
            $error = 1;
            print("
           alert('Sorry, server returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring);
       }
       
        if ($error == 0) {       
         echo "OK";
            }
        
            
        $soapClient = new SoapClient("http://technet.rapaport.com/WebServices/RetailFeed/RetailFeed.asmx?wsdl");
        
       
        // Setup the RemoteFunction parameters
        $ap_param = array(
                        'Shape'    =>    'ROUND',
                           'SizeFrom'    =>    'double',
                        'SizeTo'    =>    'double',
                           'ColorFrom'    =>    'D',
                        'ColorTo'    =>    'M',
                        'ClarityFrom'    =>    'IF',
                        'ClarityTo'    =>    'I1',
                        'CutFrom'    =>    'EXCELLENT',
                        'CutTo'    =>    'FAIR',
                        'PriceFrom'    =>    'double',
                        'PriceTo'    =>    'double',
                        'Page'    =>    'int',
                        'PageSize'    =>    'int',
                        'DiamondsFound'    =>    'int'
          
        );
                   
        // Call RemoteFunction ()
        $error = 0;
        try {
            $info = $soapClient->__call("GetDiamonds", array($ap_param));
        } catch (SoapFault $fault) {
            $error = 1;
            print("
            alert('Sorry, server returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring);
        }
       
        if ($error == 0) {       
         echo "OK";
            }
        
?>


>> add a comment
Ofer
03/02/2012 07:26


1 Replies:

Hi,

Unfortunately the __setSoapHeaders method doesn't work either for PHP. The only way I know of people succeeding with PHP so far is by using an external class that does the SOAP requests, but I don't have any code samples or specific names of used libraries for this.
 
Since this is as frustrating for our clients as it is for us, we are looking for solutions for this, but this will take some time.

If someone DOES find a solution, please share it with the rest of the developers through this forum.

Regards,

Leo



>> add a comment
Leo Muller
3/4/2012 1:10:00 AM