惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
News | PayPal Newsroom
GbyAI
GbyAI
B
Blog RSS Feed
博客园_首页
Y
Y Combinator Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
D
Docker
美团技术团队
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
Forbes - Security
Forbes - Security
雷峰网
雷峰网
Help Net Security
Help Net Security
V2EX - 技术
V2EX - 技术
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Jina AI
Jina AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cloudbric
Cloudbric
T
Troy Hunt's Blog
Hacker News: Ask HN
Hacker News: Ask HN
AI
AI
P
Proofpoint News Feed
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Last Watchdog
The Last Watchdog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
Google Online Security Blog
Google Online Security Blog
S
Security Affairs
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - chance

SQLServer 2008的数据库镜像实施笔记 报表服务器无法打印 人生值得学习的81句话 人件之名言警句 将 BLOB 值写入 SQL Server 时保留资源 Reporting Service 在打印或预览时可能会导致出现空白页的原因 asp.net中如何打印ReportViewer报表 - chance - 博客园 [翻译]使用ASP.NET2.0的ReportViewer查看RDLC报表 基于消息与.Net Remoting的分布式处理架构 C#程序实现动态调用DLL的研究 javascript事件列表解说 js 操作IE游览器 window.external... 微型项目实践感悟 DELPHI:利用INI文件实现界面无闪烁多语言切换 Delphi - 利用INI文件实现界面多语言切换 SQLServer2000的数据库容量是多大? MessageBox对话框 项目经理是这样当的 SQL Server 存储过程的分页方案比拼
动态调用Webservice
chance · 2006-08-16 · via 博客园 - chance

/// ;summary;
/// 根据指定的信息,调用远程WebService方法
/// ;/summary;
/// ;param name="url";WebService的http形式的地址;/param;
/// ;param name="namespace";欲调用的WebService的命名空间;/param;
/// ;param name="classname";欲调用的WebService的类名(不包括命名空间前缀);/param;
/// ;param name="methodname";欲调用的WebService的方法名;/param;
/// ;param name="args";参数列表;/param;
/// ;returns;WebService的执行结果;/returns;
/// ;remarks;
/// 如果调用失败,将会抛出Exception。请调用的时候,适当截获异常。
/// 异常信息可能会发生在两个地方:
/// 1、动态构造WebService的时候,CompileAssembly失败。
/// 2、WebService本身执行失败。
/// ;/remarks;
/// ;example;
/// ;code;
/// object obj = InvokeWebservice("http://localhost/GSP_WorkflowWebservice/common.asmx","Genersoft.Platform.Service.Workflow","Common","GetToolType",new object[]{"1"});
/// ;/code;
/// ;/example;
private object InvokeWebservice(string url, string @namespace, string classname, string methodname, object[] args)

 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;
Type t = assembly.GetType(@namespace+"."+classname,true,true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj,args);
 }
 catch(Exception ex)
 {
throw new Exception(ex.InnerException.Message,new Exception(ex.InnerException.StackTrace));
 }
}