通过使用 System.Reflection.Emit 动态创建代码,实现从WebService对象上抽离接口。从而方便实用。
实际使用代码
string wsdl = @"http://localhost/FSQS_WebService/Service.asmx?WSDL ";
ITableWritor obj = DynWebService.GetWebServiceInterface<ITableWritor>(wsdl, "Service");
string info = obj.TestConnection();
其中ITableWritor 是如下接口
public interface ITableWritor
{
void UpdataTable(string clientID, string targetTableName, string srcName, DataTable sourceContent);
string UpdataFile(string clientID,string targetTableName,string srcname,string bufferFilePath,int type);
string TestConnection();
}
其中"Service" 是asmx文件中对应的类的类名。类"Service"上可以显示实现ITableWritor接口。也可以仅仅包含接口所有的同名同参数,同返回值得的函数、属性。(事件应该是无效的。呵呵)