C # Use the WebService communication instance of the PHP server. Note: In this example, the WebService is constructed using the SOAP method and the php plug-in NuSoap is used to build the SOAP server. Copy the code as follows :? Require_once (libnusoap. php); call NuSoap $ serve. note: In this example, the Web Service is constructed using the SOAP method and the php plug-in NuSoap is used to build the SOAP server.
The code is as follows:
Require_once ("lib/nusoap. php"); // call NuSoap
$ Server = new soap_server (); // create a soap server
$ Server-> configureWSDL ("login_service"); // Configure the WSDL
$ Namespace = "http://www.abcd9.com ";
$ Server-> wsdl-> schemaTargetNamespace = $ namespace; // Set the wsdl namespace to a http://www.abcd9.com
$ Server-> register (// register a Web service
'Login _ verifiy', // define the name
Array ('name' => 'xsd: String', 'pw '=> 'xsd: String'), // accept the parameter
Array ('Return '=> 'xsd: String'), // return
$ Namespace, // namespace
False, // soapaction: default
'Rpc ', // type: rpc or document
'Encoded', // parameter: encoded (encoding) or literal (text)
'A web method of login' // description
);
$ POST_DATA = isset ($ GLOBALS ['http _ RAW_POST_DATA '])? $ GLOBALS ['http _ RAW_POST_DATA ']: '';
$ Server-> service ($ POST_DATA); // transmits the submitted data to the soap service.
Function login_verifiy ($ user, $ pw) {// service execution content. In this example, the entered account password is displayed.
Return 'User: '. $ user. 'password:'. $ pw );
}
?>
C # client call:
The code is as follows:
[DllImport ("kernel32")] // call the api function to read the INI file. Returns the length of the string buffer.
Private static extern long GetPrivateProfileString (string section, string key, string def, StringBuilder retVal, int size, string filePath );
Private void Form1_Load (object sender, EventArgs e)
{
StringBuilder temp = new StringBuilder (256 );
GetPrivateProfileString ("system", "url", null, temp, 256, System. IO. Directory. GetCurrentDirectory () + "\ config. ini ");
// Obtain the webservice url by reading the config. ini configuration file (for the structure, see the additional content ).
Program. server_url = temp. ToString (); // The global variable server_url in Program. cs is used to store the webservice url.
}
Private void button#click (object sender, EventArgs e)
{
WebReference. login_service l = new WebReference. login_service ();
String s = l. login_verifiy (username. Text, password. Text );
MessageBox. Show (s );
}
Add config. ini:
The code is as follows:
[System]
Url = http: // fig: 100/
Movie Service uses the SOAP method and uses the php plug-in NuSoap to build a SOAP server. The code is as follows :? Require_once ("lib/nusoap. php"); // call NuSoap $ serve...