webservice示例

webservice示例webservice示例:webservice是什么:WebService是一种跨编程语言和跨操作系统平台的远程调用技术。所谓跨编程语言和跨操作平台,就是说服务端程序采用java编写,客户端程序

大家好,又见面了,我是你们的朋友全栈君。

webservice示例:

webservice是什么:

WebService是一种跨编程语言和跨操作系统平台的远程调用技术。

   所谓跨编程语言和跨操作平台,就是说服务端程序采用java编写,客户端程序则可以采用其他编程语言编写,反之亦然!跨操作系统平台则是指服务端程序和客户端程序可以在不同的操作系统上运行。

using H3.BizBus;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Services;

namespace WebApplication4
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]

        public string GetSchema(string schemaCode)
        {
            string strSchemaJson = string.Empty;
            BizStructureSchema schema = new BizStructureSchema();//创建一个业务结构
            string errorMessage = string.Empty;
            schema.Code = schemaCode;
            schema.Add(new ItemSchema("Status", "返回结果", BizDataType.String));
            schema.Add(new ItemSchema("Msg", "返回结果", BizDataType.String));
            schema.Add(new ItemSchema("bbh", "bbh", BizDataType.String));
            schema.Add(new ItemSchema("bzmc", "bzmc", BizDataType.String));
            schema.Add(new ItemSchema("czbzId", "czbzId", BizDataType.Int));
            schema.Add(new ItemSchema("id", "id", BizDataType.String));
            schema.Add(new ItemSchema("jcdId", "jcdId", BizDataType.String));
            schema.Add(new ItemSchema("jcdwtid", "jcdwtid", BizDataType.String));
            schema.Add(new ItemSchema("bzlyId", "bzlyId", BizDataType.String));
            schema.Add(new ItemSchema("xgsj", "xgsj", BizDataType.DateTime));
            schema.Add(new ItemSchema("xssx", "xssx", BizDataType.Int));
            schema.Add(new ItemSchema("zt", "zt", BizDataType.Int));
            strSchemaJson = BizStructureUtility.SchemaToJson(schema);
            //string jsStr = Newtonsoft.Json.JsonConvert.SerializeObject(schemaCode);
            return strSchemaJson;//返回JSON字符串

        }
        [WebMethod]

        public string GetSchemaList()
        {
            return string.Empty;//返回JSON字符串
        }
        //获取查询页面id和数目条数
        ///
        public string FJLdata(string json)
        {
            JObject obj = JObject.Parse(json);
            JArray jsonstr = (JArray)obj["Matcher"]["Matchers"];
            string value = jsonstr[0]["Value"].ToString();
            return value;
        }

        [WebMethod]
        public string GetList(string userCode, string schemaCode, string filter)
        {
            //调用成功
            string intrr = "a. 有程序规定:< br >(1) 应列出对于确保符合经局方批准的设计至关重要的全部产品特性,对于不能保持就会导致或可能导致完工品出现不安全情况的关键特性应单独列出;< br >(2) 对完工品的关键特性,应进行100%检验;< br >(3) 选定的样本应能充分代表该批次或该工艺方法;< br >(4) 基于验收的质量履历来调整抽样计划,若发现影响安全的不合格品,则应加严为100%检验;< br >(5) 统计检验应符合抽样规范或批准的抽样计划要求;< br >(6) 抽样计划不允许接收带有影响安全的“已知缺陷”的批次、或带有影响安全的“已知缺陷”的可接受质量等级(AQL)。";
            if (schemaCode == "D001728jianchabiaozhun")
            {
                #region
                //get方法不带参数进行调用
                string url = "http://zxf.hyjktest.top/ruoyi-admin/Jc/data/GetJcInspect?currentPage=10&pageSize=10";
                Encoding encodin = Encoding.UTF8;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                request.Accept = "text/html,application/xhtml+xml,*/*";
                request.ContentType = "application/json";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                //string thejic = reader.ReadToEnd();
                //JObject obj = JObject.Parse(thejic);
                //JArray jsonstr = (JArray)obj["data"]["list"];
                //String hingeString = Newtonsoft.Json.JsonConvert.SerializeObject(jsonstr);
                //return hingeString;//返回JSON字符串
                #endregion
                int dataCount = 0;  //返回数据条数
                int resultCodein = 0; //全局返回状态 0为成功  否则失败 
                string resultMsg = "全局返回信息"; //全局返回信息
                H3.BizBus.BizStructureSchema schema = null;
                string errorMessage = string.Empty;
                //获取BizStructureSchema字段结构
                BizStructureUtility.JsonToSchema(this.GetSchema(schemaCode), out schema, out errorMessage);
                //定义返回的数据集合,这里以返回多条数据为例
                List<BizStructure> list = new List<BizStructure>();
                //获取数据(第三方接口,第三方数据库等等,这里以DataTable为例)
                string thejic = reader.ReadToEnd();
                JObject obj = JObject.Parse(thejic);
                JArray jsonstr = (JArray)obj["data"]["list"];
                if (jsonstr != null && jsonstr.Count > 0)
                {
                    for (int i = 0; i < jsonstr.Count; i++)
                    {
                        string jsonzhuanyi= Newtonsoft.Json.JsonConvert.SerializeObject(jsonstr[i]);
                        bool czbzcunzai = jsonzhuanyi.Contains("czbzId");
                        bool xssxcunzai = jsonzhuanyi.Contains("xssx");
                        BizStructure bizStructure = new H3.BizBus.BizStructure(schema);
                        bizStructure["Status"] = "true";
                        bizStructure["Msg"] = "msg";
                        bizStructure["bbh"] = jsonstr[i]["bbh"];
                        bizStructure["bzmc"] = jsonstr[i]["bzmc"];
                        //string abc = jsonstr[i]["czbzId"].ToString();
                        if (czbzcunzai == false) {
                            bizStructure["czbzId"] = (int)12135;
                        }
                        else {  bizStructure["czbzId"] = int.Parse(jsonstr[i]["czbzId"].ToString());}

                        bizStructure["id"] = jsonstr[i]["id"];
                        bizStructure["jcdId"] = jsonstr[i]["jcdId"];
                        bizStructure["jcdwtid"] = jsonstr[i]["jcdwtid"];
                        bizStructure["bzlyId"] = jsonstr[i]["lybzid"];
                        bizStructure["xgsj"] = DateTime.Parse(jsonstr[i]["xgsj"].ToString());
                        if (xssxcunzai==false) {
                            bizStructure["xssx"] = (int)12135;
                        }
                        else
                        {
                            bizStructure["xssx"] = int.Parse(jsonstr[i]["xssx"].ToString());
                        }

                        bizStructure["zt"] = int.Parse(jsonstr[i]["zt"].ToString());
                        list.Add(bizStructure);


                    }
                    dataCount = list.Count;
                }
                ListResult listResult = new ListResult(resultCodein, resultMsg, list.ToArray(), dataCount);
                return BizStructureUtility.ListResultToJson(listResult);

            }

            else
            {
                return string.Empty;
            }
        }
       

        [WebMethod]
        //氚云后端调用的方法名
        public string Invoke(string userCode, string schemaCode, string methodName, string param)
        {
            //书写调用第三方接口方法
            return string.Empty;//返回JSON字符串
        }
    }
}

调用接口

                string url = "http://zxf.hyjktest.top/ruoyi-admin/Jc/data/GetJcInspect?currentPage=10&pageSize=10";
                Encoding encodin = Encoding.UTF8;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                request.Accept = "text/html,application/xhtml+xml,*/*";
                request.ContentType = "application/json";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/154944.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • JavaScript:三目运算符

    JavaScript:三目运算符HELLO大家好!三目运算符是一个非常简单且使用的运算符。是由两个运算符连接的三个操作数据或者表达式条件表达式?表达式1:表达式0当条件表达式为true则选择表达式1,反之false则选择表达式0举个栗子varage=15;console.log(age<18?’未成年’:’成年’);结果为:···本人写博客就是想记录一下自己所学的知识(目前正在学习中),巩固知识加深记忆,也顺便分享一下自己的所学,有什么地方写的不对,希望大家可以多多指出,让我及时改正。如果我分享的

    2022年6月17日
  • SQL2000 数据库日志 清空

    SQL2000 数据库日志 清空

    2021年4月30日
  • 深度图像基础知识(一)

    深度图像基础知识(一)深度图像(depthimage)也被称为距离影像(rangeimage),是指将从图像采集器到场景中各点的距离(深度)作为像素值的图像,它直接反映了景物可见表面的几何形状。深度图像经过坐标转换可以计算为点云数据,有规则及必要信息的点云数据也可以反算为深度图像数据。深度数据流所提供的图像帧中,每一个像素点代表的是在深度感应器的视野中,该特定的(x,y)坐标处物体到离摄像头平面最近的

    2022年4月25日
  • 文章3说话 微信商城云server创建后台

    文章3说话 微信商城云server创建后台

    2022年1月1日
  • m3u8格式视频源列表[通俗易懂]

    m3u8格式视频源列表[通俗易懂]平时,需要测试m3u8格式视频的播放,会使用一些可用的播放源,整理在这里:constsourceList=[{name:’cctv1′,src:’http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8′},{name:’cctv2′,src:’http://ivi.bupt.edu.cn/hls/cc…

    2022年6月26日
  • getattr getattribute_getparameter返回值

    getattr getattribute_getparameter返回值问题描述今天开发验证码验证功能,需要将手机号和对应的验证码设置到session中以便后面的验证,具体代码如下:1.发送验证码并把验证码保存到session中protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresponse)throwsServletException,IOException{ try{mresponse=response;St

    2022年10月31日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号