




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、c# 开发 xml webservice接口 (soap)using system; using system.collections; using system.componentmodel; using system.data; using system.diagnostics; using system.web; using system.web.services; using bx.interface; namespace webservice / service1 的摘要说明。/publicclass doservice : system.web.services.webservic
2、e /网上报销系统 webservice服务通用调用方法/接口标识 /校验码 /操作方式 (可空 )/传入的 xml 信息/ webmethod publicstring ifservice(string ifcode, string ifpass, string ifevent,string ifinfo) ifcode = ifcode.trim(); ifpass = ifpass.trim(); ifevent = ifevent.trim(); ifinfo = ifinfo.trim(); string ireceivecontract_id = system.configurat
3、ion.configurationsettings.appsettingsireceivecontract_id.trim(); string ireceivecontract_psw = system.configuration.configurationsettings.appsettingsireceivecontract_psw.trim(); string ireceivenocontract_id = system.configuration.configurationsettings.appsettingsireceivenocontract_id.trim(); string
4、ireceivenocontract_psw = system.configuration.configurationsettings.appsettingsireceivenocontract_psw.trim(); if(ifcode.equals(ireceivecontract_id) if (!ifpass.equals(ireceivecontract_psw) return icommon.createresultxml(2,); return iapplycontract.receiveapply(ifcode,ifinfo); else if (ifcode.equals(i
5、receivenocontract_id) if (!ifpass.equals(ireceivenocontract_psw) return icommon.createresultxml(2,); return iapplynocontract.receiveapply(ifcode,ifinfo); else return icommon.createresultxml(1,); /- end ifserive / * / 功能: soap xml webservice接口通用处理类/ 说明:/ 创 建 者: / 创建时间: 2007-07-04 / 修改信息:/ * using sys
6、tem; using system.xml; using system.web.services.description; using system.codedom; using system.codedom.compiler; using system.data; namespace bx.interface / soap xml webservice接口通用处理类/publicclass icommon public icommon() / / todo: 在此处添加构造函数逻辑 / /动态引用一个 xml web service / ifserive(string ifcode,stri
7、ng ifpass,string ifevent,string ifinfo) /wsdl 路径/接口服务真实类名 /接口函数方法名 /接口标识 /接口函数参数列表数组/string publicstaticstring getsoapservice(string v_wsdl, string svclsname, string v_webmethod, string v_ifcode,ref object v_args)/ 不需安装 soap toolkit 3.0 ! string v_namespace = dsv_+v_ifcode; string v_classname = v_na
8、mespace + . + svclsname; /1) 用 xml 阅读器从一个文件路径或者是网络路径中读入wsdl 文件: xmltextreader reader = new xmltextreader(v_wsdl);/ 加入 using system.xml; /2把读到的内容用servicedescription来描述: servicedescription sd = servicedescription.read(reader); / 加入 using system.web.services.description; /3)用服务导入器把得到的描述导入服务描述中: service
9、descriptionimporter sdi = new servicedescriptionimporter(); sdi.addservicedescription(sd,null ,null ); /4 )指定要动态编译的代码的命名空间: codenamespace cn = new codenamespace(v_namespace); /dynamicservices /5)指定要动态编译的代码单元: codecompileunit ccu = new codecompileunit(); /6 )把命名空间添加到动态编译的代码单元的命名空间组中去: ccu.namespaces.
10、add(cn); /7 )指示服务导入器把该动态编译单元内该命名空间的代码导进去,作为新的动态服务描述: sdi.import(cn,ccu); /8 )新建一个 c# 编译器来编译: icodecompiler icc = new microsoft.csharp.csharpcodeprovider().createcompiler(); /9) 新建一个编译参数对象(在这里我们设置它为空的编译参数): compilerparameters cp=new compilerparameters(); /10)指示 c# 编译器,按照 cp 编译参数对象提供的参数来进行 ccu 单元的编译。并
11、把编译结果传给编译结果对象 cr : compilerresults cr = icc.compileassemblyfromdom(cp, ccu); /11 )从动态编译结果中获取某个 字符串(通常是该类型名字)所表示的真实类: type t = cr.compiledassembly.gettype(v_classname); / 其中的 dynamicservices必须和 codenamespace cn = new codenamespace(dynamicservices);定义的同名 /12)创建该类的实例: object obj = activator.createinsta
12、nce(t); /13 )根据方法名称字符串反射到该方法的实体: system.reflection.methodinfo mi = obj.gettype().getmethod(v_webmethod); /14 )用该方法实体的 .invoke()来调用该方法:string ret = system.convert.tostring(mi.invoke(obj, v_args); /,new object传给方法的参数1, 传给方法的参数2); return ret; / 添加 web 引用,在 wsdl 一栏中把刚才得到的wsdl 地址复制过来, web 引用的名称输入javaserv
13、ice / javaservice.serviceservice bean = new javaservice.serviceservice(); / string aa = bean.ifservice(ifuser,ifpass,ifcode,ifevent,info); /- end getsoapservice/ /创建返回结果 xml /接口结果代码 /错误信息堆栈 /接口结果信息 /string publicstaticstring createresultxml(int v_ifresult,string v_iferrstack,string v_ifresultinfo) s
14、tring v_iferror = ; switch (v_ifresult) case 1: v_iferror = 无此接口标识ifcode; break ; case 2: v_iferror = 调用系统校验未通过 ; break ; case 3: v_iferror = 传入的不是一个正确的xml 格式; break ; case 4: v_iferror = info参数中的字段不符合规约中的要求; break ; case 5: v_iferror = 该条数据已重复发送 ; break ; case 9: v_iferror = 本系统处理时发生异常; break ; def
15、ault : break ; xmldocument xmldoc; /xmlnode xmlnode; xmlelement xmlelem; xmldoc = new xmldocument(); / 加入 xml 的声明段落 , xmldeclaration xmldecl; xmldecl = xmldoc.createxmldeclaration(1.0,gb2312,null ); xmldoc.appendchild (xmldecl); / 加入一个根元素 xmlelem = xmldoc.createelement (,ifresponse,); xmldoc.appendc
16、hild (xmlelem) ; / 加入另外一个元素 /for(int i=1;i3;i+) / xmlnode root = xmldoc.selectsinglenode(ifresponse);/ 查找 xmlelement eifresult = xmldoc.createelement(ifresult);/ 创建一个 节点 eifresult.setattribute(note,接口结果代码 ); / 设置该节点 note 属性 eifresult.innertext = v_ifresult.tostring(); / 设置节点文本值 root.appendchild(eifr
17、esult); / 添加到 节点中 xmlelement eiferror = xmldoc.createelement(iferror); eiferror.setattribute(note,错误信息 ); eiferror.innertext = v_iferror; root.appendchild(eiferror); xmlelement eiferrorstack = xmldoc.createelement(iferrorstack); eiferrorstack.setattribute(note,错误信息堆栈 ); eiferrorstack.innertext = v_i
18、ferrstack; root.appendchild(eiferrorstack); xmlelement eifresultinfo = xmldoc.createelement(ifresultinfo); eifresultinfo.setattribute(note,接口结果信息 ); eifresultinfo.innertext = v_ifresultinfo; root.appendchild(eifresultinfo); / /保存创建好的 xml 文档 /xmldoc.save ( server.mappath(data.xml) ) ; return xmldoc.i
19、nnerxml; /xmldoc.outerxml; / / / 接口结果代码 / 错误信息 / 错误信息堆栈 / 接口结果信息 / / / 依照下述约定:/ 成功: 0 仅表示接口调用成功,并不代表业务调用成功,业务返回结果信息存放于节点中/ 失败:非零整数值/ 1:无此接口标识ifcode / 2:调用系统校验未通过/ 3:传入的不是一个正确的xml 格式/ 4:info 参数中的字段不符合规约中的要求/ 5:该条数据已重复发送/ 9:本系统处理时发生异常 /- end createresultxml/ /将 xml 格式字符串转化成dataset /xml 字符串 /datasetpub
20、licstatic dataset parseresultxml2dataset(string xml) dataset ds = new dataset(); / 方法一using (system.io.stringreader sr = new system.io.stringreader(xml) ds.readxml(sr); / /方法二/ using(system.xml.xmlreader xr = system.xml.xmlreader.create(new system.io.stringreader(xml) / / ds.readxml(xr); / / /方法三/ u
21、sing(system.io.stream st = new system.io.memorystream(system.text.encoding.utf8.getbytes(xml) / / ds.readxml(st); / return ds; /将 xml 格式字符串转化成istructresult /xml 字符串 /istructresultpublicstatic istructresult parseresultxml2struct(string xml) istructresult structresult = new istructresult(); structresu
22、lt.clear(); xmldocument xmldoc = new xmldocument(); try xmldoc.loadxml(xml); catch (xmlexception ex) structresult.ifresult = -1; structresult.iferror = 未能处理的异常返回结果; structresult.iferrorstack = ex.message; return structresult; /throw ex; try string strresult = xmldoc.getelementsbytagname(ifresult).it
23、em(0).innertext.trim(); structresult.ifresult = strresult.equals(string .empty)?-1:int .parse(strresult); structresult.iferror = xmldoc.getelementsbytagname(iferror).item(0).innertext.trim(); structresult.iferrorstack = xmldoc.getelementsbytagname(iferrorstack).item(0).innertext.trim(); structresult
24、.ifresultinfo = xmldoc.getelementsbytagname(ifresultinfo).item(0).innertext.trim(); catch (exception e) structresult.ifresult = -1; structresult.iferror = 未能处理的异常返回结果; structresult.iferrorstack = e.message; return structresult; /throw e; return structresult; /接口返回结果结构体/publicstruct istructresult pub
25、licint ifresult; publicstring iferror; publicstring iferrorstack; publicstring ifresultinfo; publicvoid clear() ifresult = -1; iferror = ; iferrorstack = ; ifresultinfo = ; using system; using system.xml; using system.io; namespace bx.interface / iapplycontract 的摘要说明。/publicclass iapplycontract publ
26、ic iapplycontract() / / todo: 在此处添加构造函数逻辑 / /接收合同付款申请信息/publicstaticstring receiveapply(string interfaceid, string xml) xmldocument xmldoc = new xmldocument(); try xmldoc.loadxml(xml); catch (xmlexception ex) /throw ex; return icommon.createresultxml(3,ex.message,); try action = xmldoc.getelementsby
27、tagname(action).item(0).innertext.trim(); . . /xml节点解析 / . . catch (exception e) /throw e; return icommon.createresultxml(4,e.message,); string strsql = insert into dbo.bx_apply_interface () values(); try / 检测是否重复提交string sqljudge = select max(receive_time) as lsttime from dbo.bx_apply_interface; sq
28、ljudge += where prjid=+contract_prjid+ and cttid=+contract_cttid+ and expandid=+contract_expandid+; object objtime = bx.dal.dbhelper.executescalar(sqljudge); if (objtime != dbnull.value) string lsttime = convert.tostring(objtime).trim(); if (!lsttime.equals(string .empty) return icommon.createresult
29、xml(0,该条数据已于 +lsttime+成功传入网上报销系统! n 操作忽略! ,0); /return icommon.createresultxml(5,该条数据已于 +lsttime+成功传入网上报销系统!n 不能重复提交! ,1); bx.dal.dbhelper.executenonquery(strsql); catch (system.data.sqlclient.sqlexception exsql) /throw exsql; return icommon.createresultxml(9,exsql.message,1); return icommon.creater
30、esultxml(0,0); using system; using system.xml; using system.data; namespace bx.interface / isendauditresult 的摘要说明。/publicclass isendauditresult /调用网上报销审批系统传递审批结果信息接口/istructresultpublicstaticstring invoke(structauditresult v_struct) string wsdl = system.configuration.configurationsettings.appsettingsisendauditresult_wsdl; string svclsname = system.configuration.configurationsettings.appsettingsisendauditresult_sv
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 本科html考试试题及答案
- 北京高中数学考试卷子及答案
- N6-Allylamino-carbonothioyl-lysine-13C6-15N2-生命科学试剂-MCE
- 电焊工焊接知识培训总结课件
- hu3S193-生命科学试剂-MCE
- 保险金融资格考试题库及答案
- 新解读《GB-T 2999-2016耐火材料 颗粒体积密度试验方法》
- 高楼居民安全知识培训课件
- 电炉操作知识培训课件
- 电源线缆安全知识培训课件
- 学校家庭教育指导(班主任培训班) 课件
- 骨关节结核教案
- 部编版一年级上册语文研课标说教材课件
- 楼板厚度检测报告
- 纳米材料ppt课件精品课件
- 精神发育迟滞课件
- 最新VTE指南解读(静脉血栓栓塞症的临床护理指南解读)
- 旅行社计调实务课件完整版电子教案
- 乌有先生传(原文+注释+译文)精编版
- DB53∕T 1022-2021 三七栽培技术规程
- 【老师必备】部编版三年级语文上册第一单元【集体备课】
评论
0/150
提交评论