Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.

SOAP

letter.wsdl 
 
<definitions
  Name="LetterCreator"
  targetNamespace="urn:m"
  xmlns:m="http://myidentifier.at"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">
 
  <types>
    <xsd:schema targetNamespace="http://myidentifier.at">
      <xsd:complexType name="letter">
        <xsd:all>
          <xsd:element name="greeting" type="xsd:string"/>
          <xsd:element name='lines' maxOccurs='unbounded'>
            <xsd:complexType name="line">
              <xsd:all>
                <xsd:element name="lineContent" type="xsd:string"/>
                <xsd:element name="lineEnd" type="xsd:string"/>
              </xsd:all>
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="farewell" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>
    </xsd:schema>
  </types>    
             
  <message name="createLetterRequest">
    <part name="recipient" type="xsd:string"/>
    <part name="text" type="xsd:string"/>
    <part name="sender" type="xsd:string"/>
  </message>
  <message name="createLetterResponse">
    <part name="complete_letter" type="m:letter"/>
  </message>
   
  <portType name="LetterCreatorPort">
    <operation name="createLetter">
      <input message="m:createLetterRequest"/>
      <output message="m:createLetterResponse"/>
    </operation>
  </portType>
 
  <binding name="LetterCreatorBinding" type="m:LetterCreatorPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="createLetter">
      <soap:operation soapAction="urn:LetterCreator#createLetter"/>
      <input><soap:body use="literal" namespace="urn:m"/></input>
      <output><soap:body use="literal" namespace="urn:m"/></output>
    </operation>
  </binding>
 
  <service name='LetterCreator'>
    <port name="LetterCreatorPort" binding="m:LetterCreatorBinding">
      <soap:address location="[url of the service]"/>
    </port>
  </service>
 
</definitions>
 
 
server.php 
 
<?php
  class Letter {
    function createLetter($recipient,$text,$sender) {
      $letter = new StdClass();
      $letter->greeting= "dear $recipient,";
      $first_line = new StdClass();
      $first_line->lineContent = "$text";
      $first_line->lineEnd= ".";
      $second_line = new StdClass();
      $second_line->lineContent = "And how is the weather";
      $second_line->lineEnd= "?";
      $letter->lines=array($first_line,$second_line);
      $letter->farewell= "yours,\n$recipient";
      return $letter;
    }
  }
 
  if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $test = new Letter;
    header('content-type: text/plain');
    print_r($test->createLetter('you','???','me'));
  }
 
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    ini_set("soap.wsdl_cache_enabled","0");
    $server = new SoapServer('letter.wsdl');
    $server->setClass('Letter');
    $server->handle();
    exit;
  }
?>
 
 
client.php 
 
<?php
  ini_set("soap.wsdl_cache_enabled","0");
  $client = new SoapClient('letter.wsdl',array('trace'=>1));
  $result = $client->createLetter('someone','how are you?','someone else');
 
  header('content-type: text/plain');
 
   print_r($result);
 
  $doc = new DOMDocument('1.0');
  $doc->formatOutput = true;
  $doc->loadXML($client->__getLastRequest());
  print $doc->saveXML();
 
  $doc = new DOMDocument('1.0');
  $doc->formatOutput = true;
  $doc->loadXML($client->__getLastResponse());
  print $doc->saveXML();
?>
Letzte Änderung: 29.04.2021, 11:14 | 515 Worte