First the results picture——
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 this web service to be called from a script using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class ibmfashion : System.Web.Services.WebService {
Public ibmfashion () {
//If using designed components, please uncomment the following 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';
//Parameters are converted to arrays and passed
$ary = array('a' => 11, 'b' => 22);
$result = $client->call('multiplication',$ary);
echo "
".print_r($result,true)."";
//Error and debug information
if ($client->fault) {
echo '
';<br> print_r($result);<br> echo '';
' . $err . '';
';<br> print_r($result);<br> echo '';
' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '';
Find the configuration file php.ini file and open the following extension
extension = php_soap.dll
extension = php_curl.dll
extension = php_openssl.dll
The PHP calling code 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:
Also use php_soap.dll, but 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:
NuSoap is a WebService programming tool in the PHP environment, used to create or call WebService. It is an open source software, which is a series of PHP classes written entirely in PHP language that sends and receives SOAP messages through HTTP. It is developed by NuSphere Corporation (http://dietrich.ganx4.com/nusoap/). One advantage of NuSOAP is that it does not require extension library support. This feature allows NuSoap to be used in all PHP environments and is not affected by server security settings.
During the processing process, be sure to pay attention to whether the parameters provided by WebService match and are correct.