Create a Web service using the php5 soapserver extension (1)

Source: Internet
Author: User
Tags soap wsdl



Learning several languages, sometimes looking back, but found no accumulation, but they also like to show off, how they are unwilling to degenerate, and forced himself to write a diary, but their own dialogue and feel boring, think of the log as a tutorial, to the community pair did not do for reference. Little brother really has no experience, Also hope that those who see this article of the fate of the people to forgive ....



PHP5 has a development Web service extension Extension=php_soap.dll;
Add the above extension to the php.ini and configure the following options for the INI file
Name Default Changeable Changelog
soap.wsdl_cache_enabled "1" php_ini_all Available since PHP 5.0.0.
Soap.wsdl_cache_dir "/tmp" Php_ini_all Available since PHP 5.0.0.
Soap.wsdl_cache_ttl "86400" Php_ini_all Available since PHP 5.0.0.
This will allow you to use the SoapServer.
Then build a document that reads as follows
<?php
Class Service_class {
/**
* @return String
* */
function SayHello () {
Return "Hello World";
}
/**
* @param string $name;
* @return string;
*/
function GetName ($name) {
return $name;
}
}


$server = new SoapServer (' buildin.wsdl ');(1)
$server->setclass (' Service_class ');(2)
$server->handle ();(3)

?>
One thing to note here is that if you want to type the WSDL file that you are generating, you should use the method annotation; (String,integer, etc.).

(1) Generate an instance where the parameter "BUILDIN.WSDL" is the location of the WSDL file because the SoapServer has not yet provided an implementation of the build WSDL because it indicates where the thin WSDL file resides.
(2) Register the provided method of webservice, default to all methods inside the class
(3) processing the request;

To get here, Access this PHP file in the browser if it appears if prompted
"Cant find http_raw_post_data"; Before you create SoapServer, insert the following code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if (!isset ($HTTP _raw_post_data)) {
$HTTP _raw_post_data = file_get_contents (' php://input ');
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

At this point, if you are prompted for errors such as bad request, the Web service has been started.

If you hadn't forgotten the WSDL in front of you, you would be thinking now that you can't generate a WSDL file, then where does that buildin.wsdl come from, and if you're familiar with Zend Studio, you'll think of the WSDL Generator under the tool menu, right, With this tool can generate very handsome WSDL file, use the method here is not much said, oneself on two will know is how to generate.

This concludes the server end.
Let the day come first here, tomorrow to continue Delphi client if calling ...

<

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.