Create a new WebService:Finance.asmx in VS2010
The code is as follows:
usingSystem.Web.Services;namespacewebtest.webservice{/// <summary> ///Summary description of Finance/// </summary>[WebService (Namespace ="http://tempuri.org/")] [WebServiceBinding (ConformsTo=Wsiprofiles.basicprofile1_1)] [System.ComponentModel.ToolboxItem (false)] //to allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream. //[System.Web.Script.Services.ScriptService] Public classFinance:System.Web.Services.WebService {[WebMethod] Public intAddintAintb) {returnA +b; } }}
New PHP File: test.php
The code is as follows:
<?PHP$client=NewSoapClient (' http://localhost/WebService/Finance.asmx?wsdl ');if($client!==false){ //solve Chinese garbled problem $client->soap_defencoding = ' Utf-8 '; $client->decode_utf8 =false; $client->xml_encoding = ' Utf-8 '; //using associative arrays, key names correspond to the parameter names of C # methods $params=Array(' A ' = 1, ' b ' + = 2); //You can use the $client->__soapcall () or $client->webservice method name () two ways to call//use $client->__soapcall () call when the $param should be wrapped again First Floor Try { $result=$client->__soapcall ("Add",Array("Parameters" =$params)); Print_r($result-Addresult); Echo"<br/>"; //Use the $client->webservice method name () call without a separate package $param $params=Array(' a ' = = 3121, ' b ' = 2); $result=$client->add ($params); Print_r($result-Addresult); } Catch(Exception $ex) { Echo $ex-GetMessage (); }}?>
PHP calls C # WebService