Preparations:
1. Install IIS support for PHP. Refer to here.
2. nusoap is required to call the web service. You only need to obtain nusoap. php and place it in the place where the PHP file to be run can be referenced. For example, you can put it in the same directory.
You can download the latest version of nusoap from here, but it seems that SourceForge has been harmonized recently?
3. to create a C # web service, let alone this. I used the wizard of vs2008 to create a simple one and run it in: http: // localhost/webservice1/service1.asmx.
There is a web method like this: 1 [webmethod]
2 Public String helloworld ()
3 {
4 return "Hello World ";
5}
OK. Everything is ready. Write the following statement in a PHP file: 1 <? PHP
2require_once ('nusoap. php ');
3/* index. php */
4 $ client = new soapclient ('HTTP: // localhost/webservice1/service1.asmx? WSDL ', true );
5 $ STR = $ client-> call ('helloworld ');
6if (! $ Err = $ client-> geterror ())
7 {
8 Echo "Return:", $ STR ['helloworldresult'];
9}
10 else
11 {
12 echo "error:", $ err;
13}
14?>
The first time I started this PHP code, I had to agree.
This method is not easy to use. When phpeclipse is used for compilation, an error is reported:
Debug strict (PHP 5):/localizationtest/nusoap. php line 6496-assigning the return value of new by reference is deprecated
Compile error:/localizationtest/nusoap. php line 7240-cannot redeclare class soapclient
Some people say that you can modify nusoap. php by changing the name to eliminate this error, which is always inconvenient. Later we found that PhP5 itself supports soap to call Web Service: <? PHP
// Get localization strings from C # WebService
$ Client = new soapclient ('HTTP: // localhost/webservice1/localization. asmx? WSDL ');
Echo "call web service method from C # WebService: \ n ";
$ Result = $ client-> getlocalizationresource ();
If (! Is_soap_fault ($ result ))
{
Echo "Return: \ n", $ result-> getlocalizationresourceresult;
}
Else
{
Echo "Soap call fault ";
}
?>
For details about PhP soap calls, refer to here