动态调用webservice 返回 out 类型参数的有关问题
动态调用webservice 返回 out 类型参数的问题?
昨天也碰到这样一个问题,动态调用webservice,然后需要进行分页的方法,但是返回的是一个datatable对象。
动态调用的方法如下:
昨天也碰到这样一个问题,动态调用webservice,然后需要进行分页的方法,但是返回的是一个datatable对象。
动态调用的方法如下:
public static object GetServiceFunction(string functionName, object[] args, params Type[] types)
{
object result = 0;
WebClient client = new WebClient();
Stream stream = null;
String url = ConfigManager.GetConfigString("TransferReservateApp", "serviceUrl"); ;//这个地址可以写在Config文件里面,这里取出来就行了.在原地址后面加上: ?WSDL
try
{
stream = client.OpenRead(url);
}
catch (WebException webex)//若使ip地址改变导致的错误,读取本地文件
{
}
ServiceDescription description = ServiceDescription.Read(stream);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();//创建客户端代理代理类。
importer.ProtocolName = "Soap"; //指定访问协议。
importer.Style = ServiceDescriptionImportStyle.Client; //生成客户端代理。
importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
importer.AddServiceDescription(description, null, null); //添加WSDL文档。
CodeNamespace nmspace = new CodeNamespace(); //命名空间
nmspace.Name = "PreService";
CodeCompileUnit unit = new CodeCompileUnit();
unit.Namespaces.Add(nmspace);
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameter = new CompilerParameters();
parameter.GenerateExecutable = false;
parameter.OutputAssembly = "MyTest.dll";//输出程序集的名称
parameter.ReferencedAssemblies.Add("System.dll");
parameter.ReferencedAssemblies.Add("System.XML.dll");