using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Sunlib;

using System.Net;

using System.IO;

using System.Web.Services.Description;

using System.CodeDom;

using Microsoft.CSharp;

using System.CodeDom.Compiler;

using System.Reflection;

public class Webservice

{

public static object InvokeWebService(string url , string methodName , object[] args)

{

string @namespace="client";

StringBuilder sb = new StringBuilder();

try

{

WebClient ws = new WebClient();

Stream stream=ws.OpenRead(url+"?WSDL");

ServiceDescription sd=ServiceDescription.Read(stream);

string classname=sd.Services[0].Name;

ServiceDescriptionImporter sdi=new ServiceDescriptionImporter();

sdi.AddServiceDescription(sd,"","");

CodeNamespace cn=new CodeNamespace(@namespace);

CodeCompileUnit ccu= new CodeCompileUnit();

ccu.Namespaces.Add(cn);

sdi.Import(cn,ccu);

CsharpCodeProvider csc=new CsharpCodeProvider();

//设定编译参数

CompilerParameters cplist=new CompilerParameters();

cplist.GenerateExecutable=false;

cplist.GenerateInMemory=true;

cplist.ReferencedAssemblies.Add("System.dll");

cplist.ReferencedAssemblies.Add("System.XML.dll");

cplist.ReferencedAssemblies.Add("System.Web.Services.dll");

cplist.ReferencedAssemblies.Add("System.Data.dll");

//编译代理类

CompilerResults cs =csc.CompileAssemblyFormDom(cplist,ccu);

if(cs.Errors.HasErrors)

{

foreach(CompilerError ce in cs.Errors)

{

sb.Append(ce.ToString()).AppendLine();

}

throw new Exception(sb.ToString());

}

Assembly assembly =cs.CompiledAssembly;

Type t = assembly.GetType(@namespace+"."+classname,true,true);

object obj =Activator.CreateInstance(t);

MethodInfo mi=t.GetMethod(methodName);

return mi.Invoke(obj,args);

}

catch(Exception e)

{

sb.Append(e.Message).AppendLine();

return null;

}

finally

{

LogHelper.WriteTxt(sb.ToString());

}

}

}

public class UpdateData

{

public dynamic UpdateDatas(params string[] args)

{

//user用户名;pwd密码

string result=Webservice.InvokeWebService(WebServiceURL,MethodName,new object[]{ user,pwd,args[0],args[1],args[2],args[3] }).ToString();

//string result=Webservice.InvokeWebService(WebServiceURL,MethodName,new object[]{args }).ToString();

}

}

public class synsReadData

{

public void ReadData()

{

//

UpdateData updateData=new  UpdateData();

dynamic rlt=updateData.UpdateDatas(userCode,meterCode,markTime,markData);

//dynamic rlt=updateData.UpdateDatas(result.ToString());//result为json数据

if(rlt==null)

{

sb.Append("WebService调用异常返回null").AppendLine();

continue;

}

//返回调用结果

string execCode=rlt.RetInfo.Code.ToString();

}

}

根据Webservice地址,动态传入参数(Webservice代理类)的更多相关文章

  1. 动态sql语句和动态传入参数个数

    1.可以将要传入的几个参数封装成一个实体类,然后将实体类作为一个参数传入到相应的方法中,这时候就需要这sqlMapper.xml文件中对传入的字段利用<if test=""& ...

  2. RF--执行案例时动态传入参数方法

    通过在运行界面的设定-v 参数值来动态传入:

  3. mybatis 框架动态传入参数${}和#{}之间的区别

    动态SQL是mybatis的强大特性之一,mybatis在对sql语句进行预编译之前,会对sql进行动态解析,解析为一个BoundSql对象,也是在此处对动态sql进行处理.下面让我们先来熟悉下myb ...

  4. PHP如何动态传入参数

    首先需要说明的是,URL写作/index.php/xx/b/c可以直接被index.php文件接受,而不用做任何额外的操作 但是如果需要在URL中隐藏index.php的话,才需要伪静态重写规则,将^ ...

  5. 动态得到WCF的代理类并生成代码

    Uri uri = new Uri("http://localhost:6580/Service1.svc?wsdl");             MetadataExchange ...

  6. 动态调用WebService的代理类

    using System; using System.Collections; using System.ComponentModel; using System.Data; using System ...

  7. webservice接口测试wsdl,参数是xml格式。python,入参转化成str,返回值转化成dict调用

    1.用SoapUI测试webservice接口,传入参数是xml格式时.xml格式需要将xml的外围增加<![CDATA[xml]]> 2.但是用python去做webservice测试, ...

  8. Unity生成WebService代理类

    普通的.net程序中,如果我们想引用webService,只需在项目中右键选择添加服务引用,然后在地址栏中输入Webservice地址,单击“转到”按钮,找到服务后再单击确定,Visual Studi ...

  9. SpringAOP-JDK 动态代理和 CGLIB 代理

    在 Spring 中 AOP 代理使用 JDK 动态代理和 CGLIB 代理来实现,默认如果目标对象是接口,则使用 JDK 动态代理,否则使用 CGLIB 来生成代理类. 1.JDK 动态代理 那么接 ...

随机推荐

  1. css控制元素高度自适应

    可以采用元素定位 + padding 的方式使特定元素高度自适应. css 样式: html,body{ height:100%; margin:; padding:; } .wrap { heigh ...

  2. Css3 笔记 动画 和定位属性

    transform 变形属性属性:translate 平移,rotate 旋转, scale 缩放,skew 倾斜 ◆ translate :指定对象的2D平移第一个参数对应X轴,第二参数对应Y轴:如 ...

  3. 关于mui前端传值,springboot后台接收值的问题

    最近做app,使用mui的ajax给后台传参,后台一直接收不到值,表示很蛋疼.这里通过网上搜索加上个人实践,总结归纳了三种前端传值和后台接收的方式. 第一种: 前端: data: JSON.strin ...

  4. July 04th. 2018, Week 27th. Wednesday

    And if you really want to see what people are, all you have to do is to look. 想真正了解他人,只需要用心看. From W ...

  5. 容器化时代我们应当选择Kubernetes

    前天发的文章<基于Kubernetes 构建.NET Core 的技术体系>,有同学问.NET Core上有Spring Cloud类似的平台吗? .NET Core出现这么久了,这个为云 ...

  6. PuppeteerSharp: 更友好的 Headless Chrome C# API

    前端就有了对 headless 浏览器的需求,最多的应用场景有两个 UI 自动化测试:摆脱手工浏览点击页面确认功能模式 爬虫:解决页面内容异步加载等问题 也就有了很多杰出的实现,前端经常使用的莫过于 ...

  7. Hadoop2.0伪分布式平台环境搭建

    一.搭建环境的前提条件 环境:ubuntu-16.04 hadoop-2.6.0  jdk1.8.0_161.这里的环境不一定需要和我一样,基本版本差不多都ok的,所需安装包和压缩包自行下载即可. 因 ...

  8. redis bind连不上的坑

    由于需要在内网其他服务器上连接redis服务器(192.168.1.110),本想直接在redis配置文件中加上目标的IP地址: bind 192.168.1.166 就可以了,实际上不正确. red ...

  9. 超级简单!把文档转换成网页格式(Core)

    因为需要把好多的文档放在服务器上访问,最开始是使用第3方网站www.aconvert.com,这个其实也挺方便的, 最后由于一些需求原因,最终只有依靠代码来进行,以下是简化后的代码 创建一个控制台应用 ...

  10. Spring Boot 面试,一个问题就干趴下了!

    最近栈长面试了不少人,其中不乏说对 Spring Boot 非常熟悉的,然后当我问到一些 Spring Boot 核心功能和原理的时候,没人能说得上来,或者说不到点上,可以说一个问题就问趴下了! 这是 ...