WebService的使用技巧

机缘

由于工作的变动,在新的公司环境下,进一步学习了WebService,并且在项目中成功使用,除了正常的功能之外总结了一些使用技巧,本篇文章将简单的介绍一下。
具体如下:

  1. 接口名称备注
  2. 接口调用数据库日志

收获

接口备注

       [WebMethod(Description = "<h1>Hello World</h1>")]
        public string HelloWorld()
        {
            string re= "Hello World";
            LogHelp.DBInfo(System.Reflection.MethodBase.GetCurrentMethod().Name, "", re);
            return re;
        }

        [WebMethod(Description = "<p>SeeSee</p>")]
        public string SeeSee(string input)
        {
            //方法处理
            string re = "SeeSee:"+input;

            //返回参数
            MsgModel msg = new MsgModel()
            {
                Code=200,
                Msg="成功",
                Data=re
            };
            //json处理
            string output = JsonConvert.SerializeObject(msg);
            //日志记录
            LogHelp.DBInfo(System.Reflection.MethodBase.GetCurrentMethod().Name,input, output);
            return output;
        }

        [WebMethod(Description = "<a href=http://www.baidu.com >百度</a>")]
        public string Baidu(string input)
        {
            //方法体处理
            string re = "您百度了:"+input;

            //返回参数
            MsgModel msg = new MsgModel()
            {
                Code=400,
                Msg="失败",
                Data=re
            };
            //json处理
            string output = JsonConvert.SerializeObject(msg);
            //日志记录
            LogHelp.DBError(System.Reflection.MethodBase.GetCurrentMethod().Name, input, output);
            return output;
        }

在这里插入图片描述

  1. 增加接口备注
  2. 使用html标签设置样式

数据库日志记录

在这里插入图片描述
上图是数据库日志示例数据。从日志内容可以清楚的看出调用的时间,接口名,调用入参,接口返回结果,等信息。有了这些信息可以很大程度的提高运维效率。


憧憬

希望本篇文章可以给大家带来一些帮助,也欢迎大家一起交流经验与批评指正。
公众号回复 “WebServiceDemo源码” 即可获得demo源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惰小懒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值