Simple example PHP calls C # WebService

Source: Internet
Author: User
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

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.