根据Webservice地址,动态传入参数(Webservice代理类)
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代理类)的更多相关文章
- 动态sql语句和动态传入参数个数
1.可以将要传入的几个参数封装成一个实体类,然后将实体类作为一个参数传入到相应的方法中,这时候就需要这sqlMapper.xml文件中对传入的字段利用<if test=""& ...
- RF--执行案例时动态传入参数方法
通过在运行界面的设定-v 参数值来动态传入:
- mybatis 框架动态传入参数${}和#{}之间的区别
动态SQL是mybatis的强大特性之一,mybatis在对sql语句进行预编译之前,会对sql进行动态解析,解析为一个BoundSql对象,也是在此处对动态sql进行处理.下面让我们先来熟悉下myb ...
- PHP如何动态传入参数
首先需要说明的是,URL写作/index.php/xx/b/c可以直接被index.php文件接受,而不用做任何额外的操作 但是如果需要在URL中隐藏index.php的话,才需要伪静态重写规则,将^ ...
- 动态得到WCF的代理类并生成代码
Uri uri = new Uri("http://localhost:6580/Service1.svc?wsdl"); MetadataExchange ...
- 动态调用WebService的代理类
using System; using System.Collections; using System.ComponentModel; using System.Data; using System ...
- webservice接口测试wsdl,参数是xml格式。python,入参转化成str,返回值转化成dict调用
1.用SoapUI测试webservice接口,传入参数是xml格式时.xml格式需要将xml的外围增加<![CDATA[xml]]> 2.但是用python去做webservice测试, ...
- Unity生成WebService代理类
普通的.net程序中,如果我们想引用webService,只需在项目中右键选择添加服务引用,然后在地址栏中输入Webservice地址,单击“转到”按钮,找到服务后再单击确定,Visual Studi ...
- SpringAOP-JDK 动态代理和 CGLIB 代理
在 Spring 中 AOP 代理使用 JDK 动态代理和 CGLIB 代理来实现,默认如果目标对象是接口,则使用 JDK 动态代理,否则使用 CGLIB 来生成代理类. 1.JDK 动态代理 那么接 ...
随机推荐
- 2.App Inventor 2编程流程
一.Chrome浏览器打开App Inventor 2编程网站注册登陆: 可选: A. http://ai2.appinventor.mit.edu/ 网速 ...
- 简单计算器 安卓 Android 作业
Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...
- App瘦身、性能优化总结
App瘦身 资源瘦身 使用tinypng压缩PNG图片.视频可以通过 Final cut等软件进行分辨率压缩.音频则降低码率即可. 非必须资源文件可以放到自己服务器上 启动图使用 LaunchScre ...
- Prncnfg.vbs参数详解
语法: Cscript Prncnfg {-g | -t | -x | -?} [-S <ServerName>] [-P <PrinterName>] [-z <New ...
- 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure
报错代码:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but se ...
- shell编写小技巧整理
1. if和else语句可以进行嵌套.if的条件判断部分可能会变得很长,可以使用逻辑运算符将它变得简洁一些. [ condition ] && action :如果condition为 ...
- Xapian索引-文档检索过程分析之匹配百分比
本文属于文档检索过程分析的一部分,重点分析文档匹配百分比(percent)的计算过程. 1 percent是什么? 我们之前分析的检索demo: Xapian::Query term_one = Xa ...
- Optimizing Java笔记:高级垃圾回收
原书地址:https://www.safaribooksonline.com/library/view/optimizing-java/9781492039259/ 感觉挺不错的一本书,断断续续在读. ...
- python接口自动化(一)--什么是接口、接口优势、类型(详解)
简介 经常听别人说接口测试,接口测试自动化,但是你对接口,有多少了解和认识,知道什么是接口吗?它是用来做什么的,测试时候要注意什么?坦白的说,笔者之前也不是很清楚.接下来先看一下接口的定义. 定义 接 ...
- ToastUtil【简单的Toast封装类】【未自定义Toast的显示风格】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 一个简单的Toast封装类. 效果图 API = 6.0 API = 4.4.2 代码分析 实现了不管我们触发多少次Toast调用, ...