机缘
由于工作的变动,在新的公司环境下,进一步学习了WebService,并且在项目中成功使用,除了正常的功能之外总结了一些使用技巧,本篇文章将简单的介绍一下。
具体如下:
- 接口名称备注
- 接口调用数据库日志
收获
接口备注
[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;
}
- 增加接口备注
- 使用html标签设置样式
数据库日志记录
上图是数据库日志示例数据。从日志内容可以清楚的看出调用的时间,接口名,调用入参,接口返回结果,等信息。有了这些信息可以很大程度的提高运维效率。
憧憬
希望本篇文章可以给大家带来一些帮助,也欢迎大家一起交流经验与批评指正。
公众号回复 “WebServiceDemo源码” 即可获得demo源码