C # uses the PHP server-side Web service Communication instance _php instance

Source: Internet
Author: User
Tags int size soap php server read ini file wsdl

Note: In this example, the Web service is constructed using a SOAP method, which is used to build the SOAP server through the PHP plug-in nusoap.

Copy Code code as follows:

?
Require_once ("lib/nusoap.php"); Call Nusoap

$server = new Soap_server (); To create a SOAP service side
$server->configurewsdl ("Login_service"); Configuring WSDL
$namespace = "http://www.abcd9.com";
$server->wsdl->schematargetnamespace = $namespace; Set WSDL namespace to http://www.abcd9.com
$server->register (//Registration of Web services
' Login_verifiy ',//definition name
Array (' name ' => ' xsd:string ', ' pw ' => ' xsd:string '),//Accept Parameters
Array (' Return ' => ' xsd:string '),//back
$namespace,//namespaces
False,//SOAPAction: Default
' RPC ',//type: RPC or document
' encoded ',//parameter: encoded (encoded) or literal (text)
' A Web method ' login '/description
);
$POST _data = isset ($GLOBALS [' http_raw_post_data '])? $GLOBALS [' Http_raw_post_data ']: ';
$server->service ($POST _data); Delivery of submitted data to the SOAP service

function Login_verifiy ($user, $PW) {//service execution, in this example, displays the password for the account entered
Return ' User: '. $user. ' Password: '. $PW);
}
?>


C # Client Invocation:

Copy Code code as follows:

[DllImport ("kernel32")]//Call API function to read INI file. The return value is 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") ;

Get WebService URL by reading config.ini configuration file (structure see additional content)
Program.server_url = temp. ToString (); Global variable Server_url in Program.cs to store WebService URLs
}

private void Button1_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);
}


Attached Config.ini content:
Copy Code code as follows:

[System]
Url=http://127.0.0.1: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.