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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mysql如何批量添加数据_mysql如何批量insert数据

    mysql如何批量添加数据_mysql如何批量insert数据mysql批量insert数据的方法:1、循环插入;2、减少连接资源,拼接一条sql;3、使用存储过程;4、使用【MYSQLLOCAL_INFILE】。本教程操作环境:windows7系统、mysql8.0.22版,该方法适用于所有品牌电脑。mysql批量insert数据的方法:方法一:循环插入这个也是最普通的方式,如果数据量不是很大,可以使用,但是每次都要消耗连接数据库的资源。大致思维如下(我…

    2022年10月23日
    0
  • 移动端开发绪论

    移动端开发绪论移动端开发基础通常移动端开发主流方案一共有两种一种是单独制作移动端页面,目前在市场上是主流方案还有一种是响应式页面兼容移动端这种虽然不是主流方案,但是应用这种开发方案的也不是没有.我们访问移动端页面可以通过以下两种方式进行访问:网址域名加m(mobile)就可以直接访问页面的移动端页面使用移动设备,进行访问,则可以直接跳转到移动端页面又到了我们最头疼的浏览器的兼容性问题移动端浏览器基本以webkit内核为主,因此我们只需要考虑webkit兼容性问题即可。移动端浏览器

    2022年6月24日
    24
  • clion2021.4激活码_通用破解码

    clion2021.4激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月17日
    42
  • 降价的路上一路狂奔 阿里云又双叒叕降价了

    降价的路上一路狂奔 阿里云又双叒叕降价了

    2022年2月23日
    33
  • MySQL安装出问题

    MySQL安装出问题

    2020年11月9日
    216
  • c语言流水灯程序详细讲解,用c语言编写单片机流水灯程序详解[通俗易懂]

    c语言流水灯程序详细讲解,用c语言编写单片机流水灯程序详解[通俗易懂]用C语言编写的单片机流水灯程序一、硬件电路因为电路用单片机控制,所以电路非常简洁。其电路原理图见下图,印制板图如下图所示。?电路的核心部分是AT89C2051单片机,前面提到它有Pl和P3两组I/O口,我们这里只用到Pl口,共8个引脚。图中Cl、R9组成典型的上电复位(即在加电时单片机复位)电路,XTAL、C2、C3与AT89C2051片内振荡电路组成时钟振荡器。值得注意的是,C2、C3的容量不能…

    2022年5月1日
    104

发表回复

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

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