VS2010+WIN7_64 + oracle11 64
这次的webservices,根据用户输入的数据,存入服务器oracle数据库。
新建空网站-新建-网站
添加新项-Web服务
选择myWebService.cs 双击,已经有存在一个HelloWord的 范例方法了。
现在可以直接点击运行看下HelloWord的效果。
现在开始编写我们自己的方法:
[WebMethod]public string AcceptBrxxInsert(string JZKH, string XM, string CSRQ, string NL, string JTZZ, string LXDH, string JDRQ, string BRXZ){try{//string JZKH_ = RequestUtil.GetString(JZKH);//string XM_ = RequestUtil.GetString(XM);//string CSRQ_ = RequestUtil.GetString(CSRQ);//string NL_ = RequestUtil.GetString(NL);//string JTZZ_ = RequestUtil.GetString(JTZZ);//string LXDH_ = RequestUtil.GetString(LXDH);//string JDRQ_ = RequestUtil.GetString(JDRQ);//string BRXZ_ = RequestUtil.GetString(BRXZ);if (String.IsNullOrEmpty(JZKH) == true){return "-1,JZKH字段不能为空!";}if (String.IsNullOrEmpty(XM) == true){return "-1,XM字段不能为空!";}#region 插入数据库string sql = "insert into YZY_BRXX (JZKH,XM,CSRQ,NL,JTZZ,LXDH,JDRQ,BRXZ) values "+ "(:JZKH,:XM,:CSRQ,:NL,:JTZZ,:LXDH,:JDRQ,:BRXZ)";List<OracleParameter> listParas = new List<OracleParameter>();listParas.Add(new OracleParameter(":JZKH", JZKH));listParas.Add(new OracleParameter(":XM", XM));if (String.IsNullOrEmpty(CSRQ) == true){listParas.Add(new OracleParameter(":CSRQ", DBNull.Value));}else{listParas.Add(new OracleParameter(":CSRQ", Convert.ToDateTime(CSRQ)));}listParas.Add(new OracleParameter(":NL", NL));listParas.Add(new OracleParameter(":JTZZ", JTZZ));listParas.Add(new OracleParameter(":LXDH", LXDH));if (String.IsNullOrEmpty(JDRQ) == true){listParas.Add(new OracleParameter(":JDRQ", DBNull.Value));}else{listParas.Add(new OracleParameter(":JDRQ", Convert.ToDateTime(JDRQ)));}listParas.Add(new OracleParameter(":BRXZ", BRXZ));if (DbHelperOra.ExecuteSql(sql, listParas.ToArray()) == 1){return "0,插入成功";}else{return "-2,失败";}#endregion}catch (Exception ex){return ("-2" + " " + ex.Message);}finally{}}[WebMethod]public string AcceptJzxxInsert(string JZKH, string JZXH, string XM, string JZRQ, string YSGH, string YSXM, string ZD1, string ZD2, string ZD3, string ICD10, string SZY, string SSY, string XL, string TZ, string ZS){try{if (String.IsNullOrEmpty(JZKH) == true){return "-1,JZKH字段不能为空!";}if (String.IsNullOrEmpty(JZXH) == true){return "-1,JZXH字段不能为空!";}if (String.IsNullOrEmpty(XM) == true){return "-1,XM字段不能为空!";}#region 插入数据库string sql = "insert into YZY_JZXX (JZKH,JZXH,XM,JZRQ,YSGH,YSXM,ZD1,ZD2,ZD3,ICD10,SZY,SSY,XL,TZ,ZS) values "+ "(:JZKH,:JZXH,:XM,:JZRQ,:YSGH,:YSXM,:ZD1,:ZD2,:ZD3,:ICD10,:SZY,:SSY,:XL,:TZ,:ZS)";List<OracleParameter> listParas = new List<OracleParameter>();listParas.Add(new OracleParameter(":JZKH", JZKH));listParas.Add(new OracleParameter(":JZXH", JZXH));listParas.Add(new OracleParameter(":XM", XM));if (String.IsNullOrEmpty(JZRQ) == true){listParas.Add(new OracleParameter(":JZRQ", DBNull.Value));}else{listParas.Add(new OracleParameter(":JZRQ", Convert.ToDateTime(JZRQ)));}listParas.Add(new OracleParameter(":YSGH", YSGH));listParas.Add(new OracleParameter(":YSXM", YSXM));listParas.Add(new OracleParameter(":ZD1", ZD1));listParas.Add(new OracleParameter(":ZD2", ZD2));listParas.Add(new OracleParameter(":ZD3", ZD3));listParas.Add(new OracleParameter(":ICD10", ICD10));listParas.Add(new OracleParameter(":SZY", SZY));listParas.Add(new OracleParameter(":SSY", SSY));listParas.Add(new OracleParameter(":XL", XL));listParas.Add(new OracleParameter(":TZ", TZ));listParas.Add(new OracleParameter(":ZS", ZS));if (DbHelperOra.ExecuteSql(sql, listParas.ToArray()) == 1){return "0,插入成功";}else{return "-2,失败";}#endregion}catch (Exception ex){return ("-2" + " " + ex.Message);}finally{}}[WebMethod]public string YZY_CFK1(string CFSB, string CFHM, string JZKH, string BRXM, string BRXZ, string CFLX, string CFRQ, string YSXM, string YSGH, string KSMC, string JZXH, string JZGH, string YSZT){try{if (String.IsNullOrEmpty(CFSB) == true){return "-1,CFSB字段不能为空!";}if (String.IsNullOrEmpty(JZKH) == true){return "-1,JZKH字段不能为空!";}if (String.IsNullOrEmpty(BRXM) == true){return "-1,BRXM字段不能为空!";}if (String.IsNullOrEmpty(JZXH) == true){return "-1,JZXH字段不能为空!";}#region 插入数据库string sql = "insert into YZY_CFK1 (CFSB,CFHM,JZKH,BRXM,BRXZ,CFLX,CFRQ,YSXM,YSGH,KSMC,JZXH,JZGH,YSZT) values "+ "(:CFSB,:CFHM,:JZKH,:BRXM,:BRXZ,:CFLX,:CFRQ,:YSXM,:YSGH,:KSMC,:JZXH,:JZGH,:YSZT)";List<OracleParameter> listParas = new List<OracleParameter>();listParas.Add(new OracleParameter(":CFSB", CFSB));listParas.Add(new OracleParameter(":CFHM", CFHM));listParas.Add(new OracleParameter(":JZKH", JZKH));listParas.Add(new OracleParameter(":BRXM", BRXM));listParas.Add(new OracleParameter(":BRXZ", BRXZ));listParas.Add(new OracleParameter(":CFLX", CFLX));if (String.IsNullOrEmpty(CFRQ) == true){listParas.Add(new OracleParameter(":CFRQ", DBNull.Value));}else{listParas.Add(new OracleParameter(":CFRQ", Convert.ToDateTime(CFRQ)));}listParas.Add(new OracleParameter(":YSXM", YSXM));listParas.Add(new OracleParameter(":YSGH", YSGH));listParas.Add(new OracleParameter(":KSMC", KSMC));listParas.Add(new OracleParameter(":JZXH", JZXH));listParas.Add(new OracleParameter(":JZGH", JZGH));listParas.Add(new OracleParameter(":YSZT", YSZT));if (DbHelperOra.ExecuteSql(sql, listParas.ToArray()) == 1){return "0,插入成功";}else{return "-2,失败";}#endregion}catch (Exception ex){return ("-2" + " " + ex.Message);}finally{}}[WebMethod]public string YZY_CFK2(string CFSB, string YPMC, string CFXH, string DJ, string SL, string FYFS, string PL, string YCJL, string JLDW, string YSZT){try{if (String.IsNullOrEmpty(CFSB) == true){return "-1,CFSB字段不能为空!";}if (String.IsNullOrEmpty(YPMC) == true){return "-1,YPMC字段不能为空!";}if (String.IsNullOrEmpty(CFXH) == true){return "-1,CFXH字段不能为空!";}#region 插入数据库string sql = "insert into YZY_CFK2 (CFSB,YPMC,CFXH,DJ,SL,FYFS,PL,YCJL,JLDW,YSZT) values "+ "(:CFSB,:YPMC,:CFXH,:DJ,:SL,:FYFS,:PL,:YCJL,:JLDW,:YSZT)";List<OracleParameter> listParas = new List<OracleParameter>();listParas.Add(new OracleParameter(":CFSB", CFSB));listParas.Add(new OracleParameter(":YPMC", YPMC));listParas.Add(new OracleParameter(":CFXH", CFXH));listParas.Add(new OracleParameter(":DJ", DJ));listParas.Add(new OracleParameter(":SL", SL));listParas.Add(new OracleParameter(":FYFS", FYFS));listParas.Add(new OracleParameter(":PL", PL));listParas.Add(new OracleParameter(":YCJL", YCJL));listParas.Add(new OracleParameter(":JLDW", JLDW));listParas.Add(new OracleParameter(":YSZT", YSZT));if (DbHelperOra.ExecuteSql(sql, listParas.ToArray()) == 1){return "0,插入成功";}else{return "-2,失败";}#endregion}catch (Exception ex){return ("-2" + " " + ex.Message);}finally{}}
本地发布
本地测试成功,现在需要发布到IIS上,供别人访问调用。
右键-发布网站 选择路径保存
IIS-添加网站
调用服务的时候会发现如下错误:
尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
查看oracle版本
如何查看oracle版本号:
用v$versions视图,如下:
SQL> select * from v$version;
BANNER
1 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
2 PL/SQL Release 11.2.0.1.0 - Production
3 CORE 11.2.0.1.0 Production
4 TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
5 NLSRTL Version 11.2.0.1.0 - Production
[应用程序池]-高级设置 修改这个即可。
其他错误:
HTTP 错误 404.17 - Not Found
请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
备注:IIS [应用程序池]- .NET Framework版本选择4.0 并且 【托管管道模式】选择“集成” 即可。