Use wsdl in PHP to create a standard webservice_PHP tutorial

Source: Internet
Author: User
Tags php online
Use wsdl in PHP to create a standard webservice. Note: Non-standard webservice may only allow PHP to access standard webservice. you must use wsdl. here I will only introduce the standard webservicewww.2cto.com. 1. create a WSDL:

• Non-standard webservice, which can only be accessed by PHP

• Standard webservice requires the use of wsdl

Here I will only introduce the standard webservice www.2cto.com

1. create a WSDL

1. Download SoapDiscovery. class. php online

2. Modify the public method getWsdl () of SoapDiscovery. class. php to automatically generate the wsdl file (note the storage path). here we only create a wsdl model.

1 // return sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,'');

2 // Generate the wsdl file and comment out the above return

3 $ fso = fopen ($ this-> class_name. ". wsdl", "w ");

4 fwrite ($ fso, sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,''));

5 exit;

3. Classes or functions that provide services

1 // for example, I have a class: person, and the file name is person. class. php.★There are two methods, one is say and the other is run. Very simple.

2

3 class person

4 {

5 public function say ()

6 {

7 return ("I'm speaking .");

8}

9 public function run ()

10 {

11 return ("I'm running, don't disturb me please .");

12}

13}

14?>

4. Start to formally generate the wsdl:

Create the file server. php. Copy the following content and run the command to generate a person. wsdl file.

1

2 include ("person. class. php ");

3 include ("SoapDiscovery. class. php ");

4 // The first parameter is the class name (the generated wsdl file is named by it), that is, the person class, and the second parameter is the service name (which can be written at will ).

5 $ disco = new SoapDiscovery ('person ', 'person ');

6 $ disco-> getWSDL ();

7?>

5. Create a webservice server program

Clear the content of the server. php file and copy the following code:

1

2 include ("person. class. php ");

3 $ objSoapServer = new SoapServer ("person. wsdl"); // person. wsdl is the newly created wsdl file.

4 // $ objSoapServer = new SoapServer ("server. php? Wsdl "); // This is also true

5 $ objSoapServer-> setClass ("person"); // register all methods of the person class

6 $ objSoapServer-> handle (); // process the request

7?>

6. Create a webservice client program and test whether the webservice is valid. the file name is client. php.

$ Client = new SoapClient ("person. wsdl ");

// $ Client = new SoapClient ("server. php? Wsdl "); // This is also true

Echo ($ client-> say ());

Echo"
";

Echo ($ client-> run ());

Echo"
";

?>

7 .. NET, you only need to provide a url for it.

Method to obtain the url: you can search for the url in the person. wsdl file first. The url here (the specific url is determined based on your Directory) is what you want to provide to. NET developers. But don't be too happy. you need to add "? Wsdl ", http: // xxxxxxxxxxxxxxxxxxxx/server. php? Wsdl is correct. if you do not believe it, you can copy the url to the address bar of the browser and check it.

. NET developers can add a service reference or web reference in their own projects after obtaining the url you have given them. then, they can complete related operations as prompted. NET developers.

(1) create a website, create a web reference, and enter the url

(2) powerful call

Protected void Page_Load (object sender, EventArgs e)

{

If (! IsPostBack ){

Sdaf. Solsoft_HelloWorld ddd = new sdaf. Solsoft_HelloWorld ();

Label1.Text = ddd. say ();

}

}

Attachment Download: http://www.BkJia.com/uploadfile/2011/1208/20111208050034814.rar

2011-12-07 21:37:56

Pale author

Non-standard webservice. you may only need PHP to access the standard webservice. you must use wsdl. here I will only introduce the standard webservice www.2cto.com. 1. create a WSDL...

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.