简体   繁体   中英

PHP soap method pass parameter

I am new to SOAP and tryign to call webservice which is hosted on somewhereelse.

I am trying to call "IsUniqueUser" webservice which check whether the user is unique or not.

Following is schema for service..

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="some service" xmlns:xsd="some xsd" xmlns:xsd1="">
 <soap:Header/>
 <soap:Body>
  <ser:isUniqueUser>
     <!--Optional:-->
     <ser:request>
    <xsd:userName>SomeValidUserName</xsd:userName>
 </ser:request>
 </ser:isUniqueUser>
 </soap:Body>
 </soap:Envelope>

And i am trying to invoke this xervice in php using following code

  $client = new SoapClient('Some.wsdl');

And after http authentication i am trying to call the isUniqueUser Method and passed "userName" as parameter.

 $unique = $client->__soapCall('isUniqueUser',  array('userName' =>'vish123'));

But nothing work out and i am getting following error

 stdClass Object
 (
[return] => stdClass Object
    (
        [errorCode] => 11ARPMWS1004
        [errorMessage] => null. null
        [status] => Failure
        [uniqueUser] => 
    )

)

I ahve tried to pass parameter in many ways like

    $params = array('UserName' =>$_POST['userName']);
    $unique = $client->__soapCall("isUniqueUser", $params);

OR

    $unique = $client->isUniqueUser($params);

OR

     $unique = $client->_soapCall('isUniqueUser', array('paramaters'=>$params));

OR

       $unique = $client->_soapCall('isUniqueUser', array('request'=>$params));

And still i am getting the same error. I have contacted with provider for this issue and they said there is something wrong with code while passing the parameter.

Can anyone please let me know how to fix this issue?

Thanks

What I can see from you request is you have xsd:userName node under "ser:request", Can you try with creating array of request having array of userName.

$params = array('UserName' =>$_POST['userName']);
$paramsrequest = array('request' =>$param);
$unique = $client->__soapCall("isUniqueUser",$paramsrequest);

see if this helps:

<?php
    $sClient = new SoapClient('Some.wsdl');
    $wrapper = null;
    $wrapper->isUniqueUser->request->userName = new SoapVar('SomeValidUserName', XSD_STRING);
    $result = $sClient->isUniqueUser($wrapper);
    echo $sClient->__getLastResponse();
?>

Also, have you tried to fire manually using some soap client like soapUI ? is it working?

In one of my project I use this :

    $soapClient = new SoapClient($wsdl,$params);
    $reponseclient=$soapClient->authentification($username,$password);
    if($reponseclient->demandeRealisee===false){
         error_log("Couldn't log ".$username);
    }

I had the same problem. I tried everything you did.

This one solved for me:

 $result = $soapClient->somefunction(array( "param1" => "value1", "param2" => "value2" )); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM