建立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 _srcWSProxy = string.Empty;
public Assembly Assembly { get{ return _ass; } }
public string ProtocolName
{ get{ return _protocolName; } set {_protocolName = value; } }
public string SrcWSProxy { 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();