使用技术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/DownloadFilesa2004-10-27WSProxy = string.Empty; public Assembly Assembly { get{ return _ass; } } public string ProtocolName { get{ return _protocolName; } set {_protocolName = value; } } public string Src/DownloadFilesa2004-10-27WSProxy { 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); } } } 猜你喜欢