This article describes how to use the WebService communication instance of the PHP server in C #. For more information, see
This article describes how to use the Web Service communication instance of the PHP server in C #. For more information, see
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
$ 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/