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


相关推荐

  • JPG 的图片格式详解

    JPG 的图片格式详解JPGjpg 全名是 JPEG JPEG 图片以 24 位颜色存储单个光栅图像 JPEG 是与平台无关的格式 支持最高级别的压缩 不过 这种压缩是有损耗的 渐近式 JPEG 文件支持交错 jpg 功能 可以提高或降低 JPEG 文件压缩的级别 但是 文件大小是以牺牲图像质量为代价的 压缩比率可以高达 100 1 JPEG 格式可在 10 1 到 20 1 的比率下轻松地压缩文件 而图片质

    2025年10月8日
    3
  • python,pandas_python常用的科学计算库

    python,pandas_python常用的科学计算库[python][科学计算][pandas]使用指南

    2022年4月21日
    44
  • Ubuntu命令备忘

    Ubuntu命令备忘

    2021年7月29日
    56
  • ubuntu16.04安装qt5_qt安装哪些组件

    ubuntu16.04安装qt5_qt安装哪些组件Qt是一个跨平台的C++图形用户界面库,我们平时所说所使用的Qt,准确的来说是它的GUI编程部分。Qt提供给应用程序开发者建立图形用户界面所需要的功能,并且Qt很容易扩展。基本上,Qt和XWindow上的Motif、Openwin、GTK等图形界面库和Windows平台上的MFC、OWL、VCl以及ATl是相同类型的东西。一.安装Qt第一步:http://download.qt.io/ar……

    2022年10月15日
    4
  • 软硬件版本号命名规范及原则是什么_文件版本号怎么编

    软硬件版本号命名规范及原则是什么_文件版本号怎么编1.软件版本阶段说明 Alpha版:此版本表示该软件在此阶段主要是以实现软件功能为主,通常只在软件开发者内部交流,一般而言,该版本软件的Bug较多,需要继续修改。 Beta版:该版本相对于α版已有了很大的改进,消除了严重的错误,但还是存在着一些缺陷,需要经过多次测试来进一步消除,此版本主要的修改对像是软件的UI。 RC版:该版本已经相当成熟了,基本上不存在导致错误的BUG,与即将发行的正式版相差无几。 Release版:该版本意味“最终版本”,在前面版本的一系列

    2025年10月20日
    3
  • pycharm怎么设置编码格式_python3设置编码为utf8

    pycharm怎么设置编码格式_python3设置编码为utf81、打开要设置的文件;2、左上角file中的Settings…3、看下图,选中Editor的FileEncodings,然后在右边选择你想要的的编码格式

    2022年8月26日
    10

发表回复

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

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