Calling web services using PHP SoapClient - how?

I'm crazy with web services. I am trying to call the following WSDL using PHP and keep getting nowhere:

http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl

I found the following code on the network, someone with similar problems, but I could not get it to work:

<code> $ soap = new SoapClient (' http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg /SessionCreateRQ.wsdl ', array (' trace '=> true,' soap_version '=> SOAP_1_2, "exceptions" => 0));

$ eb = new EbXmlMessage ();
$ sec = new Security ();
$ scrq = new SessionCreateRQ ();

try {
  $ omg = $ soap-> SessionCreateRQ ($ scrq, $ sec, $ eb);
  }
catch (Exception $ e)
{
  print_r ($ e);
}
// debug
  print "Request: \ n".
        htmlspecialchars ($ soap → __ getLastRequestHeaders ()). "\ n";
  print "Request: \ n".
         htmlspecialchars ($ soap → __ getLastRequest ()). "\ n";
  print "Response: \ n".
         $ Soap → __ getLastResponseHeaders () "\ n" ;.
  print "Response: \ n".
         $ Soap → __ getLastResponse () "\ n" ;.

print_r ($ OMG);
// first envelope headers
class EbXmlMessage
{
  public $ From = array ('PartyId' => 'mysite.com');
  public $ To = array ('PartyId' => 'myprovider.com');
  public $ CPAId = 'ZZZZ';
  public $ ConversationId = ' myconv@id.com ';
  public $ Service = 'Session'; // or SessionCreate?
  public $ Action = 'SessionCreateRQ';
  public $ MessageData = array ('MessageId' => 'messageid', 'Timestamp' => '2009-04-18T15: 15: 00Z');
   

}
// security token security
class {
  public $ Username = "xxxxx";
  public $ Password = "yyyyy";
  public $ Organization = "ZZZZ";
  public $ Domain = "DEFAULT";
}
// this is confirmed as a payload, or xml I need to send at the end of the
class SessionCreateRQ
{
  public $ POS = array (
          'Source' => array (
              '_' => "",
              'PseudoCityCode' => 'ZZZZ'
          ));
}

Code>
I keep getting the following error:

Answer: Internal HTTP / 1.1 server error 500 SOAPAction: "" Content-Type: text / xml; charset = utf-8 Date: Sun, Apr 19, 2009 10:21:34 PM GMT Connection: close Server: SWS

Answer:

soap-env: Client.InvalidEbXmlMessageUnable messagejavax.xml.soap.SOAPException: com.sun.xml.messaging.saaj.soap.MessageImpl. (MessageImpl.java:135)    com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:32)    com.sabre.universalservices.gateway.control.SoapProcessor.getRequest(SoapProcessor.java:263)    com.sabre.universalservices.gateway.control.WSGateway.handleRequest(WSGateway.java:380)    com.sabre.universalservices.gateway.control.WSGateway.doPost(WSGateway.java:306)    javax.servlet.http.HttpServlet.service(HttpServlet.java:710) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)    org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)    org.apache.coyote.http11.Http11AprProtocol $Http11ConnectionHandler.process(Http11AprProtocol.java:584)    org.apache.tomcat.util.net.AprEndpoint $Worker.run(AprEndpoint.java:1508)    java.lang.Thread.run(Thread.java:595) : javax.xml.soap.SOAPException: Content-Type: application/soap + xml at com.sun.xml.messaging.saaj.soap.MessageImpl.verify(MessageImpl.java:159)    com.sun.xml.messaging.saaj.soap.MessageImpl. (MessageImpl.java:91)   ... 19

SoapFault (     [: protected] = >     [string: private] = > .....

, - (?), .

!!!

+2
4

, , , SoapFault faultcode:

[faultcode] => soap-env:Client.InvalidEbXmlMessage

, .

EbXmlMessage XSD , , .

0

Content-type text/xml?

0

nuSOAP. PHP- SoapClient. nuSoap wsdl, , . nuSOAP :

:

<?php
// include the SOAP classes
require_once('nuSOAP/lib/nusoap.php');

function HelloWorld(){
return 'HelloWorld'; // Returns HelloWorld string
}

function Hello($name){
return 'Hello '.$name; // Returns Hello with name string parameter
}



// create the server object
$server = new nusoap_server();

// Initialize WSDL support
$server->configureWSDL('webservicenamespace', 'urn:webservicenamespace');



$server->register('HelloWorld',             array(), array('result' => 'xsd:string')); //xsd:string; xsd:boolean; xsd:integer and so on..
$server->register('Hello',                  array('name' => 'xsd:string'), array('result' => 'xsd:string')); // array('parametername' => 'parametertype'),array('result' => 'returntype');


if (isset($error))
{
    $fault =
            $server->fault('soap:Server','',$error);
}

// send the result as a SOAP response over HTTP $HTTP_RAW_POST_DATA
$post = file_get_contents('php://input');
$server->service($post);
?>

:

<?php
// Pull in the NuSOAP code
require_once('nuSOAP/lib/nusoap.php');

// Create the client instance

$client = new nusoap_client('http://pathtourl/sample_webservice.php?wsdl', true);

// Check for an error
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}

// Call the SOAP method
$result = $client->call('Hello', array('name' => 'Scott')); // Call function name, parameters;

// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
    echo '</pre>';
    }
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

Now that you want to make a client, you need your wsdl, can you just get it by adding? wsdl to your ie link (webservice.php? wsdl)

Hope this helps :) Good luck with your web service.

0
source

Source: https://habr.com/ru/post/1706688/


All Articles