Jump to content

SOAPclient


PHP_TRY_HARD

Recommended Posts

I am making my own SOAP client that needs to call from a preexisting web service.  I can access the WSDL that they supplied, so I need to build the SOAPclient backwards.  I don't really know what I am doing so would appreciate any help.  Thank you in advance.

 

THE WSDL XML

POST *****/PriceCalculationWS.asmx HTTP/1.1
Host: ***.***.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost/DriveAwayPriceCalculation/PriceCalculation"

<?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>
    <AuthHeader xmlns="http://localhost/DriveAwayPriceCalculation/">
      <UserName>string</UserName>
      <Password>string</Password>
      <errorMessage>string</errorMessage>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <PriceCalculation xmlns="http://localhost/DriveAwayPriceCalculation/">
      <requestObject>
        <UserName>string</UserName>
        <Password>string</Password>
        <CompanyCode>int</CompanyCode>
        <MLP>double</MLP>
        <OptionsPrice>double</OptionsPrice>
        <DealerDeliveryCharge>double</DealerDeliveryCharge>
        <DriveAwayCalculationFlag>N or Y</DriveAwayCalculationFlag>
        <HybridVehicle>N or Y</HybridVehicle>
        <PrivateOrBusinessUse>P or B</PrivateOrBusinessUse>
        <VehicleTareWeight>double</VehicleTareWeight>
        <EngineCapacity>int</EngineCapacity>
        <NumberOfCylinders>int</NumberOfCylinders>
        <Postcode>string</Postcode>
        <CombinedCyclefuelConsumption>double</CombinedCyclefuelConsumption>
        <InsurerCode>string</InsurerCode>
        <ElectricVehicle>N or Y</ElectricVehicle>
        <GVR>char</GVR>
      </requestObject>
    </PriceCalculation>
  </soap:Body>
</soap:Envelope>

 

Annd My PHP SOAPclient attempt


<?php
  require_once('nusoap.php');
  
  $client = new nusoap_client('https://****.asmx',true);
  
  $auth_array = array(
    'user_auth' => array(
      'UserName' => 'Username',
      'password' => 'Password',
  'errorMessage' => 'error processing data',
    )
);
  
//Here is where we actually send the data. We are calling the 'login' SOAP method 
  $login_results = $client->call('login',$auth_array);


// The following lines will use the set_entry SOAP call to add
// a Lead from a mixture of POST variables and hard coded
// values, then assign to the authenticated user...
$set_entry_params = array(
                     
                       'module_name' => 'PriceCalculation',
                       'name_value_list'=>array(
                           array('name'=>'UserName', UserName '),  
                           array('name'=>'Password',' Password '),
                           array('name'=>'CompanyCode', '00'),
                           array('name'=>'MLP', 'double'),
                           array('name'=>'OptionsPrice', 'double'),
                           array('name'=>'DealerDeliveryCharge','double'),
                           array('name'=>'DriveAwayCalculationFlag','Y'),
                           array('name'=>'PrivateOrBusinessUse','P'),
					   array('name'=>'VehicleTareWeight','2000'),
					   array('name'=>'EngineCapacity','2600'),
					   array('name'=>'NumberOfCylinders','4'),
					   array('name'=>'Postcode','2600'),
					   array('name'=>'Postcode','value'=>$_POST['Postcode']),
					   array('name'=>'CombinedCyclefuelConsumption','double'),
					   array('name'=>'InsurerCode','767'),
					   array('name'=>'ElectricVehicle','N')));

$result = $soapclient->call('set_entry',$set_entry_params);

echo "The Drive Away price for the car is $VehicleDriveAwayPrice";
?>

 

Link to comment
Share on other sites

I have the body working now but still struglling with the headers.

 

Any advice?? :confused:

 

$SOAPAction = 'http://localhost/test'; //Namespace of the WS. 
//
$AuthHeader = array('TestUser' => $UserName, 
               'TestPassword' => $Password,
		   '' => $errorMessage);

$client = new nusoap_client("https://testWS.asmx?WSDL", true);


$headers = new SoapHeader('http://localhost/test', 'AuthHeader', true); 

 

I am using nuSOAP

Link to comment
Share on other sites

I fixed it, I think it is cheating a little but it has given me the result I wanted.  I just added the XML code to the headers.

$client->setHeaders("<AuthHeader xmlns=\"http://localhost/test/\"><UserName>User123</UserName><Password>Password123</Password><errorMessage></errorMessage></AuthHeader>");    

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.