2

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 = .NET

SOAP 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.

1 Answer 1

2

You need to generate the php classes from the wsdl file. http://www.urdalen.no/wsdl2php/index.php

Sign up to request clarification or add additional context in comments.

1 Comment

thank you lisa. im going to look into how to use these classes with my client...any useful articles you know of?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.