Namespace microshaoft
{
Using system;
Using system. IO;
Using system. Web. Services. Protocols;
Public class gzipsoapextension: soapextension
{
Private stream _ originalstream;
Private stream _ workstream;
Public override stream chainstream (Stream)
{
_ Originalstream = stream;
_ Workstream = new memorystream ();
Return _ workstream;
}
Public override object getinitializer
(
Logicalmethodinfo methodinfo
, Soapextensionattribute
)
{
Return NULL;
}
Public override object getinitializer (type webservicetype)
{
Return NULL;
}
Public override void initialize (Object initializer)
{
// To do...
}
Public override void processmessage (soapmessage message)
{
Switch (message. stage)
{
Case soapmessagestage. beforeserialize:
Break;
Case soapmessagestage. afterserialize:
Compressstream ();
Break;
Case soapmessagestage. beforedeserialize:
Decompressstream ();
Break;
Case soapmessagestage. afterdeserialize:
Break;
Default:
Throw new exception ("invalid stage ");
}
}
Public void compressstream ()
{
// Compression response
Stream stream = compresshelper. gzipcompress (_ workstream );
Byte [] buffer = compresshelper. readstreamtobytes (Stream );
_ Originalstream. Write (buffer, 0, buffer. Length );
}
Public void decompressstream ()
{
// Extract the request
Byte [] bytes = compresshelper. readstreamtobytes (_ originalstream );
Bytes = compresshelper. gzipdecompress (bytes );
_ Workstream. Write (bytes, 0, bytes. Length );
_ Workstream. Position = 0;
}
}
[Attributeusage (attributetargets. Method)]
Public class gzipsoapextensionattribute: soapextensionattribute
{
Private int _ priority;
Public override int priority
{
Get
{
Return _ priority;
}
Set
{
_ Priority = value;
}
}
Public override type extensiontype
{
Get
{
Return typeof (gzipsoapextension );
}
}
}
}
Namespace microshaoft
{
Using system;
Using system. text;
Using system. IO;
Using system. Io. compression;
Public class compresshelper
{
Public static byte [] readstreamtobytes (Stream)
{
Byte [] buffer = new byte [64*1024];
Int r = 0;
Int L = 0;
Long position =-1;
If (stream. canseek)
{
Position = stream. position;
Stream. Position = 0;
}
Memorystream MS = new memorystream ();
While (true)
{
R = stream. Read (buffer, 0, buffer. Length );
If (r> 0)
{
L + = R;
Ms. Write (buffer, 0, R );
}
Else
{
Break;
}
}
Byte [] bytes = new byte [l];
Ms. Position = 0;
Ms. Read (bytes, 0, (INT) L );
Ms. Close ();
MS = NULL;
If (position> = 0)
{
Stream. Position = position;
}
Return bytes;
}
Public static byte [] gzipcompress (byte [] data)
{
Memorystream MS = new memorystream ();
Gzipstream stream = new gzipstream (MS, compressionmode. Compress, true );
Stream. Write (data, 0, Data. Length );
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
Byte [] buffer = readstreamtobytes (MS );
Ms. Close ();
Ms. Dispose ();
MS = NULL;
Return buffer;
}
Public static byte [] gzipdecompress (byte [] data)
{
Memorystream MS = new memorystream (data );
Gzipstream stream = new gzipstream (MS, compressionmode. Decompress );
Byte [] buffer = readstreamtobytes (Stream );
Ms. Close ();
Ms. Dispose ();
MS = NULL;
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
Return buffer;
}
Public static stream gzipcompress (Stream Data)
{
Byte [] buffer = readstreamtobytes (data );
Memorystream MS = new memorystream ();
Gzipstream stream = new gzipstream (MS, compressionmode. Compress, true );
Stream. Write (buffer, 0, buffer. Length );
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
If (Ms. canseek)
{
Ms. Position = 0;
}
Return MS;
}
Public static stream gzipdecompress (Stream Data)
{
Byte [] buffer = readstreamtobytes (data );
Memorystream MS = new memorystream (buffer );
Gzipstream stream = new gzipstream (MS, compressionmode. Decompress );
If (stream. canseek)
{
Stream. Position = 0;
}
Return stream;
}
Public static byte [] deflatecompress (byte [] data)
{
Memorystream MS = new memorystream ();
Deflatestream stream = new deflatestream (MS, compressionmode. Compress, true );
Stream. Write (data, 0, Data. Length );
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
Byte [] buffer = readstreamtobytes (MS );
Ms. Close ();
Ms. Dispose ();
MS = NULL;
Return buffer;
}
Public static byte [] deflatedecompress (byte [] data)
{
Memorystream MS = new memorystream (data );
Deflatestream stream = new deflatestream (MS, compressionmode. Decompress );
Byte [] buffer = readstreamtobytes (Stream );
Ms. Close ();
Ms. Dispose ();
MS = NULL;
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
Return buffer;
}
Public static stream deflatecompress (Stream Data)
{
Byte [] buffer = readstreamtobytes (data );
Memorystream MS = new memorystream ();
Deflatestream stream = new deflatestream (MS, compressionmode. Compress, true );
Stream. Write (buffer, 0, buffer. Length );
Stream. Close ();
Stream. Dispose ();
Stream = NULL;
If (Ms. canseek)
{
Ms. Position = 0;
}
Return MS;
}
Public static stream deflatedecompress (Stream Data)
{
Byte [] buffer = readstreamtobytes (data );
Memorystream MS = new memorystream (buffer );
Deflatestream stream = new deflatestream (MS, compressionmode. Decompress );
If (stream. canseek)
{
Stream. Position = 0;
}
Return stream;
}
}
}
// ================================================ ========================================================== ================================
// WebService. asmx
// <% @ WebService Language = "C #" class = "microshaoft. service1class" DEBUG = "true" %>
Namespace microshaoft
{
Using system. diagnostics;
Using system. Web;
Using system. Web. Services;
Using system. Collections. Generic;
Using system. Data;
[WebService (namespace = "http://www.microshaoft.com/")]
Public class service1class: WebService
{
[Webmethodattribute]
[Microshaoft. gzipsoapextension ()]
Public String helloworld (string X)
{
Return string. Format ("Hello {0}", x); // +;
}
[Webmethod]
[Microshaoft. gzipsoapextension ()]
Public dataset helloworld1 (Dataset X)
{
X. Tables [0]. Rows [0] [1] + = "\ tserver ";
Return X; // string. Format ("Hello {0}", x); // +;
}
}
Public class extends esponse
{
Public string name;
Public int age;
Public byte [] data;
}
Public class implements equest
{
Public string name;
Public int age;
}
}
// ================================================ ========================================================== ================================
// Proxy client
Namespace consoleapplication
{
Using system;
Using system. Data;
Using proxy;
/// <Summary>
/// Summary of class1.
/// </Summary>
Public class class1
{
/// <Summary>
/// Application Program .
/// </Summary>
// [Stathread]
Static void main (string [] ARGs)
{
//
// Todo: add Code To start the application
//
Service1class x = new service1class ();
String S = x. helloworld ("Yuxi ");
Console. writeline (s );
Dataset d = x. helloworld1 (createdataset ());
String Ss = D. Tables [0]. Rows [0] [1]. tostring ();
Console. writeline (SS );
Console. writeline (environment. version. tostring ());
}
Private Static dataset createdataset ()
{
Dataset dataset = new dataset ();
// Create two datatable objects using a function.
Datatable Table1 = maketable ("idtable1", "thing1 ");
Datatable Table2 = maketable ("idtable2", "thing2 ");
Dataset. Tables. Add (Table1 );
Dataset. Tables. Add (table2 );
Return dataset;
// Console. writeline (Dataset. Tables. Count)
}
Private Static datatable maketable
(
String c1name
, String c2name
)
{
Datatable table = new datatable ();
// 'Add two datacolumns
Datacolumn column = new datacolumn (c1name, typeof (INT ));
Table. Columns. Add (column );
Column = new datacolumn (c2name, typeof (string ));
Table. Columns. Add (column );
Table. Rows. Add (1, "AA ");
Table. Rows. Add (2, "BB ");
Return table;
}
}
}
Namespace proxy
{
//------------------------------------------------------------------------------
// <Auto-generated>
// This code is generated by the tool.
// Runtime version: 2.0.50727.3053
//
// Changes to this file may lead to incorrect behavior, and if
// Re-generate the Code. These changes will be lost.
// </Auto-generated>
//------------------------------------------------------------------------------
Using system;
Using system. componentmodel;
Using system. Data;
Using system. diagnostics;
Using system. Web. Services;
Using system. Web. Services. Protocols;
Using system. xml. serialization;
//
// This Source code Automatically Generated by WSDL, version = 2.0.50727.42.
//
/// <Remarks/>
[System. codedom. compiler. generatedcodeattribute ("WSDL", "2.0.50727.42")]
[System. Diagnostics. debuggerstepthroughattribute ()]
[System. componentmodel. designercategoryattribute ("Code")]
[System. Web. Services. webservicebindingattribute (name = "service1classsoap", namespace = "http://www.microshaoft.com/")]
Public partial class service1class: system. Web. Services. Protocols. soaphttpclientprotocol {
Private system. Threading. sendorpostcallback helloworldoperationcompleted;
Private system. Threading. sendorpostcallback helloworld1operationcompleted;
/// <Remarks/>
Public service1class (){
This. url = "http://test.v20.asp.net/SoapExtension/Noname1.asmx ";
}
/// <Remarks/>
Public event helloworldcompletedeventhandler helloworldcompleted;
/// <Remarks/>
Public event helloworld1completedeventhandler helloworld1completed;
/// <Remarks/>
[System. web. services. protocols. soapdocumentmethodattrispace ("http://www.microshaoft.com/HelloWorld", requestnamespace = "http://www.microshaoft.com/", responsenamespace = "http://www.microshaoft.com/", use = system. web. services. description. soapbindinguse. literal, parameterstyle = system. web. services. protocols. soapparameterstyle. wrapped)]
[Microshaoft. gzipsoapextension ()]
Public String helloworld (string X ){
Object [] Results = This. Invoke ("helloworld", new object [] {
X });
Return (string) (results [0]);
}
/// <Remarks/>
Public System. iasyncresult beginhelloworld (string X, system. asynccallback callback, object asyncstate ){
Return this. begininvoke ("helloworld", new object [] {
X}, callback, asyncstate );
}
/// <Remarks/>
Public String endhelloworld (system. iasyncresult asyncresult ){
Object [] Results = This. endinvoke (asyncresult );
Return (string) (results [0]);
}
/// <Remarks/>
Public void helloworldasync (string X ){
This. helloworldasync (x, null );
}
/// <Remarks/>
Public void helloworldasync (string X, object userstate ){
If (this. helloworldoperationcompleted = NULL )){
This. helloworldoperationcompleted = new system. Threading. sendorpostcallback (this. onhelloworldoperationcompleted );
}
This. invokeasync ("helloworld", new object [] {
X}, this. helloworldoperationcompleted, userstate );
}
Private void onhelloworldoperationcompleted (Object Arg ){
If (this. helloworldcompleted! = NULL )){
System. Web. Services. Protocols. invokecompletedeventargs invokeargs = (system. Web. Services. Protocols. invokecompletedeventargs) (ARG ));
This. helloworldcompleted (this, new helloworldcompletedeventargs (invokeargs. Results, invokeargs. error, invokeargs. cancelled, invokeargs. userstate ));
}
}
/// <Remarks/>
[System. web. services. protocols. soapdocumentmethodattrispace ("http://www.microshaoft.com/HelloWorld1", requestnamespace = "http://www.microshaoft.com/", responsenamespace = "http://www.microshaoft.com/", use = system. web. services. description. soapbindinguse. literal, parameterstyle = system. web. services.