Php calls the webservice Interface (. net Interface)

Source: Internet
Author: User
Instance code 1: try {$ this-soapClientObjnewSoapClient (self: URL .? Wsdl, array (connection_timeoutself: CONNECTION_TIMEOUT);} catch (Exception $ e) {thrownewException ($ e-getMessage (), $ e-getCode ());} instance Code 2 :? Phpheader (

Instance 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 ();} instance Code 2 :? Php header ("

Instance 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 ());
}

Instance Code 2:

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
$ Client = new SoapClient ($ ws );
/*
* Obtain all methods provided by the Service referenced by the SoapClient object
*/
Echo 'open functions provided by the SOAP server :';
Echo'

';
Var_dump ($ client->__ getFunctions (); // obtain the method provided on the server
Echo "";


Echo 'Type provided by the SOAP server :';
Print_r ($ client->__ getTypes (); // obtain the data type on the server
Echo "";


Echo 'result of executing GetGUIDNode :';
// Query the weather in Beijing, China. A struct is returned.
$ Result = $ client-> getWeather (array ('cityname' => 'beijing', 'countryname' => 'China '));
Echo $ result-> GetWeatherResult; // display the result

?>

Running result:

Example of try and catch

Eg:

// Create a function that can throw an exception
Function checkNum ($ number ){
If ($ number> 1 ){
Throw new Exception ("Value must be 1 or below ");
}
Return true;
}


// Trigger an exception in the try code block
Try {
// If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below ';
CheckNum (2 );

} Catch (Exception $ e ){
// Capture exceptions
Echo 'message: '. $ e-> getMessage ();
}

?>

The above code will get an error similar to this:

Message: Value must be 1 or below 
Example:

The above code throws an exception and captures it:

  1. Create the checkNum () function. It checks whether the number is greater than 1. If yes, an exception is thrown.
  2. Call the checkNum () function in the "try" code block.
  3. An exception in the checkNum () function is thrown.
  4. The "catch" code block receives the exception and creates an object ($ e) containing the exception information ).
  5. Call $ e-> getMessage () from this exception object to output error messages from this exception.

However, to follow the "each throw must correspond to a catch" principle, you can set a top-level exception processor to handle missed errors.

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.