First, the result chart--
C # code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Using System.Web.Services.Protocols;
///
Summary description of Ibmfashion
///
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[SoapDocumentService (Routingstyle = soapserviceroutingstyle.requestelement)]
To allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream.
[System.Web.Script.Services.ScriptService]
public class Ibmfashion:System.Web.Services.WebService {
Public Ibmfashion () {
If you are using a design component, uncomment the line
InitializeComponent ();
}
[WebMethod]
public string HelloWorld () {
Return "Hello World";
}
[WebMethod]
public int multiplication (int a, int b)
{
return a*b;
}
}
PHP calls C # WebService code:
Pull in the Nusoap code
Ob_start ();
Require_once (' lib/nusoap.php ');
$url = "HTTP://LOCALHOST:8787/WCF/IBMFASHION.ASMX?WSDL";
$client = new Nusoap_client ($url, ' WSDL ', ', ', ', ', ');
$client->soap_defencoding= ' Utf-8 ';
$client->decode_utf8=false;
$client->xml_encoding= ' Utf-8 ';
Parameter conversions are passed to an array
$ary = Array (' a ' + =, ' b ' = + 22);
$result = $client->call (' multiplication ', $ary);
echo "
". Print_r ($result, true)."
";
Error and debug information
if ($client->fault) {
Echo '
Fault
';
Print_r ($result);
Echo '
';
} else {
Check for errors
$err = $client->geterror ();
if ($err) {
Display the error
Echo '
Error
' . $err. '
';
} else {
Display the result
Echo '
Result
';
Print_r ($result);
Echo '
';
}
}
Display the Debug messages
Echo '
Debug
';
Echo '
' . Htmlspecialchars ($client->debug_str, ent_quotes). '
';
?>
Summarize some common methods that PHP calls C #. NET WebService:
Act 1:
Check whether the System32 directory has php_soap.dll, if not downloaded to this directory.
Locate the configuration file PHP.ini file, and open the following extension
Extension = Php_soap.dll
Extension = Php_curl.dll
Extension = Php_openssl.dll
The code for the PHP call is as follows:
Method 1:
$url = "HTTP://WWW.WS.CN/1/HEALTHGROW/SERVICE.ASMX?WSDL";
$client = new SoapClient ($url);
$client->soap_defencoding= ' Utf-8 ';
$client->decode_utf8=false;
$client->xml_encoding= ' Utf-8 '
$result = $client->__soapcall ("Userlogin", Array ("Userlogin" =>array (
' str ' = ' + ' {"UserName": "3", "Password": "222"} '));
if (Is_soap_fault ($result)) {
Trigger_error ("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_user_ ERROR);
}
Else
{
Echo Print_r ("return:". $result->userloginresult,true);
}
Method 2:
The same is true with Php_soap.dll, except that the code is slightly different:
$url = "HTTP://WWW.WS.CN/1/HEALTHGROW/SERVICE.ASMX?WSDL";
$client = new SoapClient ($url);
$client->soap_defencoding= ' Utf-8 ';
$client->decode_utf8=false;
$client->xml_encoding= ' Utf-8 ';
$result = $client->userlogin (Array (' str ' = ' = ' {' UserName ': ' 3 ', ' Password ': ' 222 '} '));
if (Is_soap_fault ($result)) {
Trigger_error ("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_user_ ERROR);
}
Else
{
Echo Print_r ("return:". $result->userloginresult,true);
}
Method 3:
Using Nusoap is a WebService programming tool for creating or invoking webservice in a PHP environment. It is an open source software, developed by Nusphere Corporation (http://dietrich.ganx4.com/nusoap/), a series of PHP classes written entirely in PHP that send and receive SOAP messages over HTTP. One advantage of Nusoap is that there is no need for extended library support, which allows Nusoap to be used in all PHP environments and is not affected by server security settings.
It is important to note that the parameters provided by WebService are matched and correct during the process.
http://www.bkjia.com/PHPjc/477901.html www.bkjia.com true http://www.bkjia.com/PHPjc/477901.html techarticle first, the result diagram C # code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Ser vices; Using System.Web.Services.Protocols; //...