There is a ready-made nusoap on the Internet, and I am not using it. if it is used, I may not know how PHP creates webservice. there is a ready-made nusoap on the internet. I am not using it. if it is used, I may not know how PHP creates a webservice.
1. create a wsdl
Note:
A. Non-standard webservice, which can only be accessed by PHP
B. The standard webservice must use wsdl (webservice description language, which is used to describe your service content in XML syntax standards, which I understand)
Here I will only introduce the standard webservice.
How to create a wsdl? For PHP, this is really not easy. some people say that it is very convenient to create with zend studio. this is a method. But for those who do not like zend studio, they will feel that it is too difficult to create a webservice and install zend studio. I am, hey.
Here I will introduce a simple method to download SoapDiscovery online. class. php class, which has a public method: getWSDL. The return is used at the end of this method. so, you can modify this method. I did this:
// Return sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,'');
// Generate the wsdl file and comment out the above return
$ Fso = fopen ($ this-> class_name. ". wsdl", "w ");
Fwrite ($ fso, sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,''));
The generated wsdl class now has SoapDiscovery. class. php★.
I only need to prepare a service-providing class or function to create the wsdl.
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.
There are two classes: SoapDiscovery. class. php and person. class. php.
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.
GetWSDL ();?>
2. create a webservice server program
Clear the content of the server. php file and copy the following code:
SetClass ("person"); // all methods for registering the person class $ objSoapServer-> handle (); // process the request?>
3. create a webservice client and test whether the webservice is valid. the file name is client. php.
Copy the following content
Say (); echo"
"; Echo ($ client-> run (); echo"
";?>
OK. Is it easy?
If you want to use. 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 ", scheme.
. 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.
Here I will only introduce the standard webservice.
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.
// Return sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,''); // Generate the wsdl file and annotate the above return comments $ fso = fopen ($ this-> class_name. ". wsdl "," w "); fwrite ($ fso, sprintf ('% s % s', $ headerWSDL, $ portTypeWSDL, $ bindingWSDL, $ serviceWSDL, $ messageWSDL ,''); Exit;
3. Classes or functions that provide services
// 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.
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.
GetWSDL ();?>
5. Create a webservice server program
Clear the content of the server. php file and copy the following code:
SetClass ("person"); // all methods for registering the person class $ objSoapServer-> handle (); // process the request?>
6. Create a webservice client program and test whether the webservice is valid. the file name is client. php.
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 ", scheme.
. 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(); } }