当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 动态引用WebService,建立WebService虚拟机

ASP.NET
ASP.NET错误处理:Runtime Error
如何使用ADO.NET Entity Framework从数据库中获取图片
ASP.NET教程:WaitHandle类
ASP.Net中Ado.Net Entity Framework实际项目应用释疑
ASP.NET页面中控制部分元素隐现的方法
asp.net网站开发中使用Sqlite嵌入式数据库
ASP.NET教程:调用WebService的源码
.NET中的垃圾回收
asp.net教程:编译错误同时存在于不同dll中
ASP.NET4.0新改进和新特性
ASP教程:防SQL注入
ASP.NET教程:HttpContext类Current属性
在Win2003 IIS 6.0中安装ASP.net环境
asp.net2.0中App_GlobalResources用途
利用Windows系统服务自动更新网站
无缝的缓存读取:双存储缓存策略
WebServices的性能特别慢是真的吗?
ASP.NET MVC的Web应用程序更直观
PHP和ASP.NET代码哪个运行速度更快?
ASP.NET常用代码

ASP.NET 中的 动态引用WebService,建立WebService虚拟机


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 91 ::
收藏到网摘: n/a

动态引用WebService概述 建立WebService虚拟代理,使用xml登记WebService的引用地址。实现动态引用WebService. 使用技术1、 动态编译2、 反射技术实现代码using System;using System.Reflection ;using System.Web .Services .Description ;using Microsoft.CSharp;using System.CodeDom ;using System.CodeDom.Compiler ;using System.IO ;using System.Text ;using System.Xml ;using System.Net ;using WebServiceProxy;namespace WebServiceProxy{ public class WebServiceProxy { private Assembly _ass = null; private string _protocolName = "Soap"; private string _src/DownloadFiles\a\2004-10-27\WSProxy = string.Empty; public Assembly Assembly { get{ return _ass; } } public string ProtocolName { get{ return _protocolName; } set {_protocolName = value; } } public string Src/DownloadFiles\a\2004-10-27\WSProxy { get{ return _srcWSProxy; } } public WebServiceProxy () { } public WebServiceProxy (string wsdlSourceName) { AssemblyFromWsdl(GetWsdl(wsdlSourceName)); } public string WsdlFromUrl(string url) { WebRequest req = WebRequest.Create(url); WebResponse result = req.GetResponse(); Stream ReceiveStream = result.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader sr = new StreamReader( ReceiveStream, encode ); string strWsdl = sr.ReadToEnd(); return strWsdl; } public string GetWsdl(string source) { if(source.StartsWith(" 0) throw new Exception(string.Format("Build failed: {0} errors", cr.Errors.Count)); return _ass = cr.CompiledAssembly; } public object CreateInstance(string objTypeName) { Type t = _ass.GetType("WebServiceProxy.WebServiceAccessor" + "." + objTypeName); return Activator.CreateInstance(t); } public object Invoke(object obj, string methodName, params object[] args) { MethodInfo mi = obj.GetType().GetMethod(methodName); return mi.Invoke(obj, args); } } }