简体   繁体   中英

PHP-Soap pass method parameters

I have relatively no experience with SOAP. Im trying to work with a webservice for a client using WSDL mode. I'm having trouble passing parameters with the method and getting them to come the parameters to show up in the request as needed. I'm using the standard php soap class.

I need my SOAP request to be structured like the following:

 <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hostserver/">
    <SOAP-ENV:Body>
        <ns1:DoLogin>
            <ns1:request>
                <ns1:Session>
                    <ns1:SessionId>00000000-0000-0000-0000-000000000000</ns1:SessionId>
                </ns1:Session>
                <ns1:UserCredential>
                    <ns1:UserName>username</ns1:UserName>
                    <ns1:Password>password</ns1:Password>
                    <ns1:ApplicationID>00000000-0000-0000-0000-000000000000</ns1:ApplicationID>
                    <ns1:ClientID>00000000-0000-0000-0000-000000000000</ns1:ClientID>
                    <ns1:ClientVersion>V1.0</ns1:ClientVersion>
                </ns1:UserCredential>
            </ns1:request>
        </ns1:DoLogin>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In php I call the function like so:

$client->DoLogin($args);

And the request ends up like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hostserver/"><SOAP-ENV:Body><ns1:DoLogin/></SOAP-ENV:Body></SOAP-ENV:Envelope>

No matter how I pass the args (single varabiables, array, class object) I cant get the request to have the structure as that.

Can anyone help me? I'm sure its going to be something quite simple.

While working on a slightly related problem today, I found that the following PHP produced the SOAP request shown below:

$sc = new SoapClient($url);
$params = array('step' => 'ShippingInfo', 'value' => "hello");
$result = $sc->__soapCall('runStep', array('parameters' => $params));
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
 <SOAP-ENV:Body>
  <ns1:runStep>
     <ns1:step>ShippingInfo</ns1:step>
     <ns1:value>hello</ns1:value>
  </ns1:runStep>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

One catch I found was that if the parameters ($params) I passed did not conform to what was specified in the WSDL file, the message that the SOAP client generated would look similar to what you complain of--a message with a body contains no data value. I wonder if your problem lies here.

Also, note how the above PHP uses two arrays to pass parameters. The first array contains the parameters and their names. The second contains the first array. Interesting syntax, I know. :-)

FYI, the example code above being used to communicate with a C# .Net WCF service having the following contract:

[OperationContract]
string runStep(string step, string value);

try this:

$soapClient->__soapCall('methodToCall', array('parameters' => $yourParamsArray));

That worked for me with a .NET webservice.

This is valid way: right mr.bgondy
$result = $soapClient->methodsomefunction("params1"=>"value","params2"=>"value2");

my question is that you said

$soapClient->__soapCall('methodToCall', array('parameters' => $yourParamsArray));

above code for .net web services but when i have tried this method for .net asp web services, parameters values not parse i think so because when i removed params=value not effect same "Unknown error occured!" from .net asp web services in iframe.

I had the same problem.

This one solved for me:

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

Parameter types (and order) must be the same as what the current wsdl defines. (string, object, etc)

试试这个,

$client->__soapCall('methodName',array('requestObj'=>$requestObj));

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