Description
• Non-standard WebService, which can only be accessed by PHP
• Standard WebService, it is necessary to use the WSDL
Here I only introduce the standard WebService www.2cto.com
First, create WSDL
1. Download SoapDiscovery.class.php class online
2. Modify the public method of SoapDiscovery.class.php getwsdl () to automatically generate the WSDL file (note the storage path), here just create a WSDL model
1//return sprintf ('%s%s%s%s%s%s ', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ');
2//Generate a WSDL file with the return comment above
3 $fso = fopen ($this->class_name. ". wsdl", "w");
4 fwrite ($fso, sprintf ('%s%s%s%s%s%s ', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, "));
5 exit;
3. The class or function that provides the service
1//For example, I have a class: person, file name: person.class.php★, there are two methods, one is say, one 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 {
One return ("I ' m running,don ' t disturb me please.");
12}
13}
?>
4. To begin the formal generation of WSDL:
Create the file server.php. Copy the following to run 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 after it), the person class, and the second parameter is the name of the service (this can be casually written).
5 $disco = new Soapdiscovery (' person ', ' person ');
6 $disco->getwsdl ();
7?>
5. Create a WebService service-side program
Empty the contents of the server.php file and copy the following code in:
1
2 include ("person.class.php");
3 $objSoapServer = new SoapServer ("person.wsdl");//person.wsdl is the WSDL file that was just created
4//$objSoapServer = new SoapServer ("server.php?wsdl");//This is OK
5 $objSoapServer->setclass ("person");//All methods of registering the person class
6 $objSoapServer->handle ();//Processing request
7?>
6. Create the WebService client program to test whether the webservice is valid and the file name is: client.php
$client = new SoapClient ("person.wsdl");
$client = new SoapClient ("server.php?wsdl");//This is OK
Echo ($client->say ());
echo "
";
Echo ($client->run ());
echo "
";
?>
7.. NET if you want to use, you just have to provide a URL to him on the line.
How to get the URL: You can find it in the person.wsdl file first, here the URL (the specific URL is determined by your directory) is what you want to provide. NET developers to use. But do not be happy too early, the following to add: "? wsdl", http://xxxxxxxxxxxxxxxxxxxx/server.php?wsdl this is the right, do not believe you can copy the URL to the browser's address bar to see it.
. NET developer gets the URL you gave him, you can add a service reference or Web reference to your project, and then you can follow the prompts to complete the operation, for use. NET developers are simple.
(1) Create a website, create a Web reference, enter a URL
(2) Strength 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
Author Dim
http://www.bkjia.com/PHPjc/478495.html www.bkjia.com true http://www.bkjia.com/PHPjc/478495.html techarticle Description: Non-standard WebService, may only PHP to access the standard webservice, you must use the WSDL here I only introduce the standard WebService www.2cto.com one, create WSDL ...