I have spent a good week looking for an answer that I can understand. I'm fairly new to the web developing world.
My problem lies with generating a soap message that requires values in attributes to be set as well as the elements themselves.
Here is an simplified example of the SOAP message I am trying to create.
Client = PHP
Server = .NETSOAP message needed:
<PingRequest EchoToken="string">
<EchoData>string</EchoData>
</PingRequest>
WSDL part
<s:element name="PingRequest" type="s0:PingRequest" />
<s:complexType name="PingRequest">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="EchoData" type="s:string" />
</s:sequence>
<s:attribute name="EchoToken" type="s:string" />
</s:complexType>
I've spent lots trying to understand how to make a class and other objects to pass to the webservice, however, my brain fails me. Apologies if my question is a little obscure. Here is my attempt at invoking my webservice:
<?php
//connection to wsdl
$client = new SoapClient('http://localhost/ws.asmx?wsdl',
array( "trace" => 1,
"exceptions" => 0
));
try {
// Ping = Function
// PingRequest = method?
$result = $client->PingRequest(array('EchoData' => 'moo'));
} catch (SOAPFAULT $f){
}
echo "\n The Result: \n";
print_r($result);
print "<pre>";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";
;
?>
Request:
<ns1:PingRequest>
<ns1:EchoData>moo</ns1:EchoData>
</ns1:PingRequest>
Any help is a thumbs up.
EDIT: thanks to lisa: i was able to create a class for this: but i still dont understand
class PingRequest {
public $EchoData; // string
public $EchoToken; // string
public $TimeStamp; // dateTime
public $Target; // PingTarget
public $Version; // decimal
public $TransactionIdentifier; // string
public $SequenceNmbr; // nonNegativeInteger
public $TransactionStatusCode; // PingRequestStatusCode
public $RetransmissionIndicator; // boolean
}
made it very 开发者_开发技巧easy. thank you
create a new class variable with name of webservice class and then create your stdclasses for each element or attribute you wish to pass. (must use the class generator lisa supplied.
You need to generate the php classes from the wsdl file. http://www.urdalen.no/wsdl2php/index.php
精彩评论