• C#编写Web设置请求报文都为application/json类型格式


    方法一:

    创建Web一般处理程序,支持json字符串格式

    请求报文例如:

    {
    "num":"0440200011510190002",
    "cls":"stkin",
    "ocrTime":"2020-7-23 12:29:30",
    "reason":"下错单了"
    }

    代码:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Web;
    using YiRan.BLL.WebApi;
    
    namespace YiRan.WebApi
    {
        /// <summary>
        /// YiRanWebHandles 的摘要说明
        /// </summary>
        public class YiRanWebHandles : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "application/json";
                string sendInfo = string.Empty;
                using (StreamReader reader = new StreamReader(context.Request.InputStream))
                {
                    sendInfo = reader.ReadToEnd().Trim();
                }
                if(string.IsNullOrWhiteSpace(sendInfo))
                {
                    context.Response.Write("传入字符串不能为空");
                    return;
                }
                ActiveStop m = new ActiveStop();
                string res = m.TaskInfo(sendInfo);
                context.Response.Write(res);
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }

     第二种 WebService

    请求报文例如:

    {

     "sendInfo":"{'num':'0440200011510190002','cls':'stkin','ocrTime':'2020-7-23 12:29:30','reason':'下错单了'}"

    }

    using Common;
    using Common.DataConversionHelper;
    using Common.Log;
    using Common.WebHttps;
    using Entitys;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Script.Services;
    using System.Web.Services;
    using YiRan.BLL;
    using YiRan.BLL.WebApi;
    using YiRan.Entity;
    using YiRan.Entity.StandardOrderCancel;
    
    namespace YiRan.WebApi
    {
        /// <summary>
        /// YiRanWebMian 的摘要说明
        /// </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 YiRanWebMian : System.Web.Services.WebService
        {
            [WebMethod(Description = "Erp主动截停单据接口(WMS提供)")]
            [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
            public void SetActiveStop(string sendInfo)
            {
                ActiveStop m = new ActiveStop();
                string res = m.TaskInfo(sendInfo);
                Context.Response.Clear();
                Context.Response.ContentType = "application/json";
                Context.Response.Write(res.ToString());
            }
        }
    }
  • 相关阅读:
    Linux下让一个程序开机自动启动
    Heartbeat高可用解决方案
    NFS文件共享
    清除系统日志的三个脚本
    nfs+rsync+inotify实现文件的实时同步
    安装配置rsync服务端
    shell中如何进行算术运算
    linux下查看账号密码的过期时间和设置时间
    配置Nginx作为web server详解
    [LeetCode] 398. Random Pick Index ☆☆☆
  • 原文地址:https://www.cnblogs.com/yuanshuo/p/16291264.html
Copyright © 2020-2023  润新知