First, the result graph --
C # code:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Using System. Web. Services. Protocols;
/// <Summary>
/// Ibmfashion abstract description
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
[SoapDocumentService (RoutingStyle = SoapServiceRoutingStyle. RequestElement)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
// [System. Web. Script. Services. ScriptService]
Public class ibmfashion: System. Web. Services. WebService {
Public ibmfashion (){
// If you use the designed component, 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:
<? Php
// 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 ';
// Convert the parameter to an array for passing
$ Ary = array ('A' => 11, 'B' => 22 );
$ Result = $ client-> call ('samples', $ ary );
Echo "<pre>". print_r ($ result, true). "</pre> ";
// Error and debug information
If ($ client-> fault ){
Echo 'Print_r ($ result );
Echo '</pre> ';
} Else {
// Check for errors
$ Err = $ client-> getError ();
If ($ err ){
// Display the error
Echo '} Else {
// Display the result
Echo 'Print_r ($ result );
Echo '</pre> ';
}
}
// Display the debug messages
Echo 'Echo '<pre>'. htmlspecialchars ($ client-> debug_str, ENT_QUOTES). '</pre> ';
?>
Summarize several common methods for php to call c #. NET webservice:
Method 1:
Check whether php_soap.dll exists in the System32 directory. If it is not downloaded online, put it in this directory.
Find the configuration file php. ini and open the following extension:
Extension = php_soap.dll
Extension = php_curl.dll
Extension = php_openssl.dll
The PHP call 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:
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. It is used to create or call WebService. It is an open source software, is fully written in PHP language, through HTTP to send and receive SOAP messages of a series of PHP class, developed by NuSphere Corporation (http://dietrich.ganx4.com/nusoap. One advantage of NuSOAP is that it does not require the support of extension libraries. This feature allows NuSoap to be used in all PHP environments and is not affected by server security settings.
During the processing, make sure that the parameters provided by WebService match and are correct.