The webservcie under the C # implements code, very simple to see what kind of function is done.
Using system; using system.componentmodel; using system.data; using system.web; using system.web.services;
A summary description of Namespace WebHelloz5 {///
#Region Component Designer Generated Code // Web Server Designer The private icontainer component = null; ///
///
// Web Service Sample // HelloWorld () Sample Service Returns Hello World // To generate, cancel the following list, then save and generate items // To test this web service, press F5 button
// [WebMethod] // public string helloworld1 () // {// return "Hello World"; //}
[WebMethod] Public String HelloWorld (int NARG, STRING STRARG) {Return Strarg Narg.toString ();
}
Below is called WebService, the packet sent on the network.
Client request data:
Post /Webhelloz5/service1.asmx http / 1.1 host: localhost content-type: text / xml content-length: length soapaction: "http://tempuri.org/helloworld"
XML Version = "1.0" encoding = "UTF-8"?>
HTTP / 1.1 200 OK Content-Type: Text / XML; Charset = UTF-8 Content-Length: Length
XML Version = "1.0" encoding = "UTF-8"?>
Automatically generated proxy class under VC7, as shown below:
template
CComptruap_spreadStream; __cservice1_helloworld_struct __params; memset (& __ params, 0x00, sizeof (__ params)); __Params.NARG = NARG; __PARAMS.STRARG = strarg;
__atlsoap_hr = SetClientStruct (& __ params, 0); if (FAILED (__ atlsoap_hr)) {SetClientError (SOAPCLIENT_OUTOFMEMORY); goto __skip_cleanup;} __atlsoap_hr = GenerateResponse (GetWriteStream ()); if (FAILED (__ atlsoap_hr)) {SetClientError (SOAPCLIENT_GENERATE_ERROR); goto __skip_cleanup ;} __atlsoap_hr = SendRequest (_T ( "SOAPAction: /"http://tempuri.org/HelloWorld/"/r/n")); if (FAILED (__ atlsoap_hr)) {goto __skip_cleanup;} __atlsoap_hr = GetReadStream (& __ atlsoap_spReadStream) ; if (FAILED (__ atlsoap_hr)) {SetClientError (SOAPCLIENT_READ_ERROR); goto __skip_cleanup;} // cleanup any in / out-params and out-headers from previous calls Cleanup (); __atlsoap_hr = BeginParse (__ atlsoap_spReadStream); if (FAILED (__ atlsoap_hr )) {SetClientError (SOAPCLIENT_PARSE_ERROR); goto __cleanup;} * HelloWorldResult = __params.HelloWorldResult; goto __skip_cleanup; __cleanup: Cleanup (); __skip_cleanup: ResetClientState (true); memset (& __ params, 0x00, sizeof (__ params)); Return__atlsoap_hr;}
The process is:
1 Initialization parameter list (setClientStruct (& __ params, 0);) | V
2. Generate Send Data Request (GetWritestReam ()); SendRequest (_T ("soapaction: /"http://tempuri.org/helloworld/"/r/N"));) | v 3. Receive and resolution Response data (BeginParse);) | V 4. Clean up work
Python code:
#author: zfive5 (zhaozidong) #Email: zfive5@yahoo.com.cn
Import httplib import xml.parsers.expat import urlparse
Class ZFive5Web: Def__init __ (Self, URL, XMLns): Self.URL = URL Self.xmlns = XMLns Self.ret = "Self.Data =" DEF GEN_REQUEST (Self, Strfunc, Strxmlns, Dictarg): Ret = "