Home > Article > Backend Development > PHP SOAP server-side C# client_PHP tutorial
Recently I wrote a SOAP server for PHP, which enabled the calling of the PHP client, but could not realize the calling of the c# client. After reading the manual, I searched for it for a long time but could not access it. Finally, I tried NuSOAP
An open source project on SF.net, the effect is very good, Eacy can achieve the required functions
C# web services (server-side) are very easy to implement, and C# client calls are also very convenient
PHP's web server generally generates a .wsdl file. .wsdl is an Xml file describing the services provided
Let’s take a look at my first PHP web service
/**
* ProcessSimpleType method
* @param string $who name of the person we'll say hello to
* @return string $helloText the hello string
*/
function ProcessSimpleType($who) {
Return "Hello $who, Welcome to visit http://www.my400800.cn ";";
}
?>
Remember to download nusoap firsthttp://www.BkJia.com/uploadfile/2011/0825/20110825031745407.zip
require_once("lib/nusoap/nusoap.php");
$namespace = "http://www.my400800.cn";
// create a new soap server
$server = new soap_server();
// configure our WSDL
$server->configureWSDL("SimpleService");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
// register our WebMethod
$server->register(
// method name:
'ProcessSimpleType',
// parameter list:
array('name'=>'xsd:string'),
// return value(s):
array('return'=>'xsd:string'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style. rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'A simple Hello World web method');
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>
You can use it after writing it
Open .net and add reference
Next click wsdl, you can see the services provided, as shown below
C# calling code
private void button1_Click(object sender, EventArgs e) {
SimpleService svc = new SimpleService();
string s = svc.ProcessSimpleType("400 phone VIP user");
MessageBox.Show(s);
}
Result