rt
谢谢了。
using System;
using System.Threading;
namespace ConsoleApplication1
{
class Class1
{
static object obj = null;
static Type t = null;
[STAThread]
static void Main(string[] args)
{
string url = "http://localhost/XMLWebServices/Chapter02/HelloWorld/Service1.asmx";
string @namespace = "HelloWorld";
string classname = "Service1";
string methodname = "HelloWorld";
AsyncCallback x_callback = new AsyncCallback(TestCallback);
object[] arg = new object[2];
arg[0] = x_callback;
arg[1] = null;
try
{
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream stream = wc.OpenRead(url+"?WSDL");
System.Web.Services.Description.ServiceDescription sd = System.Web.Services.Description.ServiceDescription.Read(stream);
System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
sdi.AddServiceDescription(sd,"","");
System.CodeDom.CodeNamespace cn = new System.CodeDom.CodeNamespace(@namespace);
System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn,ccu);
Microsoft.CSharp.CSharpCodeProvider csc = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();
System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");
System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if(true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
System.Reflection.Assembly assembly = cr.CompiledAssembly;
t = assembly.GetType(@namespace+"."+classname,true,true);
obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod("Begin"+methodname);
Console.WriteLine(mi.ToString());
mi.Invoke(obj,arg);
}
catch(Exception ex)
{
throw new Exception(ex.InnerException.Message,new Exception(ex.InnerException.StackTrace));
}
Thread.Sleep(10000);
}
private static void TestCallback(IAsyncResult p_asyncResult)
{
string x_result= null;
try
{
object[] ar = new object[2];
ar[0] = (object)p_asyncResult;
ar[1] = (object)x_result;
System.Reflection.MethodInfo mi = t.GetMethod("End"+"HelloWorld");
mi.Invoke(obj,ar);
}
catch
{
Console.WriteLine("error1");
}
Console.WriteLine(x_result+"haha");
Console.WriteLine(x_result+"haha");
}
}
}
※ 修改:·ether800 於 Sep 24 18:41:31 2004 修改本文·[FROM: 202.118.19.*]
※ 来源:·BBS 水木清华站
http://smth.org·[FROM: 202.118.19.*]
修改:ether800 FROM 202.118.19.*
FROM 202.118.19.*