PHP calls the Web service interface (. NET developed interface)

Source: Internet
Author: User
Tags soap wsdl

Example code 1:

try {
$this->soapclientobj = new SoapClient (Self::url. '? wsdl ', Array (' connection_timeout ' = self::connection_timeout));
} catch (Exception $e) {
throw new Exception ($e->getmessage (), $e->getcode ());
}

Example code 2:

<?php
Header ("content-type:text/html; Charset=utf-8 ");
/*
* Specify the WebService path and initialize a WebService client
*/
$ws = "http://www.webservicex.net/globalweather.asmx?wsdl"; address of the//webservice service
$client = new SoapClient ($WS);
/*
* Get all the methods provided by the service that the SoapClient object references
*/
Echo ' SOAP server provides an open function: ';
Echo ' <pre> ';
Var_dump ($client->__getfunctions ());//Get the method provided on the server
echo "


Echo ' SOAP server provides the type: ';
Print_r ($client->__gettypes ());//Get the data type on the server
echo "


Echo ' Execution of getguidnode results: ';
Find weather in Beijing, China returns a structure
$result = $client->getweather (Array (' cityname ' = ' Beijing ', ' countryname ' = ' China ');
echo $result->getweatherresult;//Display Results

?>

Operation Result:

Instance description of try and catch

eg

<?php

To create a function that throws an exception
function Checknum ($number) {
if ($number >1) {
throw new Exception ("Value must be 1 or below");
}
return true;
}


To trigger an exception in a "try" code block
try {
If the exception is a thrown, this text won't be shown Echo's if you see this and the number is 1 or below ';
Checknum (2);

}catch (Exception $e) {
Catching exceptions
Echo ' Message: '. $e->getmessage ();
}

?>

The above code will get an error like this:

Example Explanation:

The above code throws an exception and captures it:

    1. Create the Checknum () function. It detects if the number is greater than 1. If it is, an exception is thrown.
    2. Call the Checknum () function in the "Try" code block.
    3. The exception in the Checknum () function is thrown
    4. The catch code block receives the exception and creates an object ($e) that contains the exception information.
    5. Output the error message from this exception by calling $e->getmessage () from this exception object

However, to follow the principle that each throw must correspond to a catch, you can set up a top-level exception handler to handle the missing error.

PHP calls the Web service interface (. NET developed interface)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.