C # Use the WebService communication instance of the PHP server

Source: Internet
Author: User
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.