1、創(chuàng)建WEBAPI


1 using Dapper; 2 using MesErp.Models; 3 using Microsoft.AspNetCore.Mvc; 4 using Microsoft.Extensions.Configuration; 5 using Newtonsoft.Json; 6 using System; 7 using System.Collections.Generic; 8 using System.Data; 9 using System.Data.Common; 10 using System.Data.SqlClient; 11 using System.Linq; 12 using System.Runtime.Intrinsics.Arm; 13 using System.Security.Cryptography; 14 using System.Threading.Tasks; 15 using System.Xml.Linq; 16 namespace MesErp.Controllers 17 { 18 /// <summary> 19 /// ERP-MES基礎(chǔ)數(shù)據(jù)同步" 20 /// </summary> 21 [Route("[controller]")] 22 [ApiController] 23 public class ErpMesBasicController : ControllerBase 24 { 25 private string ConnectionStr() 26 { 27 var appSettingsJson = AppSettingsJson.GetAppSettings(); 28 string connectionString2 = appSettingsJson.GetSection("ConnectionStrings")["DefaultConnection"];//鏈接數(shù)據(jù)庫(kù)字符串 29 return connectionString2; 30 } 31 /// <summary> 32 /// 庫(kù)存組織新增/更新 33 /// </summary> 34 /// <returns></returns> 35 [HttpPost("AddWorkcenter")] 36 public async Task< ErpMesRts> AddWorkcenter([FromBody] WorkcenterModel workcenters) 37 { 38 int rst = -1; 39 ErpMesRts rstsate = new ErpMesRts(); 40 41 string connectionString = ConnectionStr();//鏈接字符串 42 DynamicParameters paras = new DynamicParameters(); 43 string Ctworkter= JsonConvert.SerializeObject(workcenters); 44 paras.Add("@JosnName", Ctworkter); 45 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 46 using (IDbConnection connection = new SqlConnection(connectionString)) 47 { 48 try 49 { 50 rst = await connection.ExecuteAsync("proc_ERP_MesAddWorkcenter", paras, commandType: CommandType.StoredProcedure); 51 } 52 catch(Exception e) 53 { 54 rstsate.msg=e.Message.ToString()+"數(shù)據(jù)庫(kù)異常"; 55 56 } 57 // 執(zhí)行存儲(chǔ)過(guò)程 58 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 59 60 } 61 if (rst > 0) 62 { 63 rstsate.status = 200; 64 rstsate.msg = "成功"; 65 } 66 67 68 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 69 return rstsate; 70 //rst 返回1為成功 71 // return Json(new { code = 200, msg = "ok" }); 72 } 73 /// <summary> 74 /// 人員主數(shù)據(jù)新增/更新 75 /// </summary> 76 /// <returns></returns> 77 [HttpPost("AddPersonInfo")] 78 public async Task<ErpMesRts> AddPersonInfo([FromBody] PersonInfoModel personInfos) 79 { 80 int rst = -1; 81 ErpMesRts rstsate = new ErpMesRts(); 82 83 string connectionString = ConnectionStr();//鏈接字符串 84 DynamicParameters paras = new DynamicParameters(); 85 string Ctworkter = JsonConvert.SerializeObject(personInfos); 86 paras.Add("@JosnName", Ctworkter); 87 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 88 using (IDbConnection connection = new SqlConnection(connectionString)) 89 { 90 try 91 { 92 rst = await connection.ExecuteAsync("proc_ERP_MesAddPersonInfo", paras, commandType: CommandType.StoredProcedure); 93 } 94 catch (Exception e) 95 { 96 rstsate.msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 97 98 } 99 // 執(zhí)行存儲(chǔ)過(guò)程 100 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 101 102 } 103 if (rst > 0) 104 { 105 rstsate.status = 200; 106 rstsate.msg = "成功"; 107 } 108 109 110 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 111 return rstsate; 112 //rst 返回1為成功 113 // return Json(new { code = 200, msg = "ok" }); 114 } 115 /// <summary> 116 /// 業(yè)務(wù)組新增/更新 117 /// </summary> 118 /// <returns></returns> 119 [HttpPost("AddBusinessGroup")] 120 public async Task<ErpMesRts> AddBusinessGroup([FromBody] BusinessGroupModel businessGroups) 121 { 122 int rst = -1; 123 ErpMesRts rstsate = new ErpMesRts(); 124 125 string connectionString = ConnectionStr();//鏈接字符串 126 DynamicParameters paras = new DynamicParameters(); 127 string Ctworkter = JsonConvert.SerializeObject(businessGroups); 128 paras.Add("@JosnName", Ctworkter); 129 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 130 using (IDbConnection connection = new SqlConnection(connectionString)) 131 { 132 try 133 { 134 rst = await connection.ExecuteAsync("proc_ERP_MesAddBusinessGroup", paras, commandType: CommandType.StoredProcedure); 135 } 136 catch (Exception e) 137 { 138 rstsate.msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 139 140 } 141 // 執(zhí)行存儲(chǔ)過(guò)程 142 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 143 144 } 145 if (rst > 0) 146 { 147 rstsate.status = 200; 148 rstsate.msg = "成功"; 149 } 150 151 152 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 153 return rstsate; 154 //rst 返回1為成功 155 // return Json(new { code = 200, msg = "ok" }); 156 } 157 /// <summary> 158 /// 組織主數(shù)據(jù)/部門(mén)主數(shù)據(jù)新增/更新 159 /// </summary> 160 /// <returns></returns> 161 [HttpPost("AddDivision")] 162 public async Task<ErpMesRts> AddDivision([FromBody] DivisionModel divisions) 163 { 164 int rst = -1; 165 ErpMesRts rstsate = new ErpMesRts(); 166 167 string connectionString = ConnectionStr();//鏈接字符串 168 DynamicParameters paras = new DynamicParameters(); 169 string Ctworkter = JsonConvert.SerializeObject(divisions); 170 paras.Add("@JosnName", Ctworkter); 171 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 172 using (IDbConnection connection = new SqlConnection(connectionString)) 173 { 174 try 175 { 176 rst = await connection.ExecuteAsync("proc_ERP_MesAddDivision", paras, commandType: CommandType.StoredProcedure); 177 } 178 catch (Exception e) 179 { 180 rstsate.msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 181 182 } 183 // 執(zhí)行存儲(chǔ)過(guò)程 184 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 185 186 } 187 if (rst > 0) 188 { 189 rstsate.status = 200; 190 rstsate.msg = "成功"; 191 } 192 193 194 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 195 return rstsate; 196 //rst 返回1為成功 197 // return Json(new { code = 200, msg = "ok" }); 198 } 199 /// <summary> 200 /// 物料類(lèi)型新增/更新 201 /// </summary> 202 /// <returns></returns> 203 [HttpPost("AddProductType")] 204 public async Task<ErpMesRts> AddProductType([FromBody] ProductTypeModel productTypes) 205 { 206 int rst = -1; 207 ErpMesRts rstsate = new ErpMesRts(); 208 209 string connectionString = ConnectionStr();//鏈接字符串 210 DynamicParameters paras = new DynamicParameters(); 211 string Ctworkter = JsonConvert.SerializeObject(productTypes); 212 paras.Add("@JosnName", Ctworkter); 213 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 214 using (IDbConnection connection = new SqlConnection(connectionString)) 215 { 216 try 217 { 218 rst = await connection.ExecuteAsync("proc_ERP_MesAddProductType", paras, commandType: CommandType.StoredProcedure); 219 } 220 catch (Exception e) 221 { 222 rstsate.msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 223 224 } 225 // 執(zhí)行存儲(chǔ)過(guò)程 226 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 227 228 } 229 if (rst > 0) 230 { 231 rstsate.status = 200; 232 rstsate.msg = "成功"; 233 } 234 235 236 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 237 return rstsate; 238 //rst 返回1為成功 239 // return Json(new { code = 200, msg = "ok" }); 240 } 241 /// <summary> 242 /// 物料主數(shù)據(jù)新增/更新 243 /// </summary> 244 /// <returns></returns> 245 [HttpPost("AddProduct")] 246 public async Task<ErpMesRts> AddProduct([FromBody] ProductModel products) 247 { 248 int rst = -1; 249 ErpMesRts rstsate = new ErpMesRts(); 250 251 string connectionString = ConnectionStr();//鏈接字符串 252 DynamicParameters paras = new DynamicParameters(); 253 string Ctworkter = JsonConvert.SerializeObject(products); 254 paras.Add("@JosnName", Ctworkter); 255 // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出參數(shù),這里為指明參數(shù)類(lèi)型大小 256 using (IDbConnection connection = new SqlConnection(connectionString)) 257 { 258 try 259 { 260 rst = await connection.ExecuteAsync("proc_ERP_MesAddProduct", paras, commandType: CommandType.StoredProcedure); 261 } 262 catch (Exception e) 263 { 264 rstsate.msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 265 266 } 267 // 執(zhí)行存儲(chǔ)過(guò)程 268 // rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure); 269 270 } 271 if (rst > 0) 272 { 273 rstsate.status = 200; 274 rstsate.msg = "成功"; 275 } 276 277 278 //"{status: = " + code + ", msg = " + msg + ", data = " + null "}"; 279 return rstsate; 280 //rst 返回1為成功 281 // return Json(new { code = 200, msg = "ok" }); 282 } 283 284 285 286 287 288 /* 289 /// <summary> 290 /// 庫(kù)存組織更新 291 /// </summary> 292 /// <param name="testModel">接收對(duì)象</param> 293 /// <returns></returns> 294 [HttpPost("UpdatWorkcenter")] 295 public async Task<string> updateBlog([FromBody] WorkcenterModel testModel) 296 { 297 //這個(gè)就代表的你第二層,懂弄?很多層都是一樣的 298 299 300 int rst = -1; 301 int code = 500; 302 string msg = "失敗"; 303 string connectionString = ConnectionStr();//鏈接字符串 304 using (IDbConnection connection = new SqlConnection(connectionString)) 305 { try 306 { // 執(zhí)行存儲(chǔ)過(guò)程 307 rst = await connection.ExecuteAsync(" UPDATE Workcenter SET WorkcenterDescription=isnull(@WorkcenterDescription,WorkcenterDescription),IsHB=@IsHB, SiteId=@SiteId,SiteName = @SiteName,IsClosed = @IsClosed WHERE WorkcenterName = @WorkcenterName ", testModel.workcenters); 308 } 309 catch (Exception e) 310 { 311 msg = e.Message.ToString() + "數(shù)據(jù)庫(kù)異常"; 312 313 } 314 } 315 if (rst > 0) 316 { 317 code = 200; 318 msg = "成功"; 319 } 320 return "{code = " + code + ", msg = " + msg + "}"; 321 } 322 323 */ 324 325 } 326 }
用restful?風(fēng)格創(chuàng)建接口
?鏈接字符串
2、webapi發(fā)布
發(fā)布路徑
?發(fā)布時(shí)選擇空文件
?選擇路徑
?發(fā)布完成示例圖
?注意編輯接口是會(huì)勾選XML輸出
?這個(gè)路徑打包編譯時(shí)是不會(huì)自動(dòng)編譯過(guò)去的
3、發(fā)布到IIS上
創(chuàng)建應(yīng)用池時(shí)(創(chuàng)建無(wú)托管、集成)
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-437242.html
?部署服務(wù)器環(huán)境需要安裝三個(gè)文件
?https://dotnet.microsoft.com/zh-cn/download/dotnet/5.0環(huán)境下載、也可參照其他鏈接https://blog.csdn.net/xiaochenXIHUA/article/details/118027591
環(huán)境安裝后需要將文件發(fā)布IIS上
?同時(shí)配置將XML文件考到發(fā)布文件里面
?
配制web.config加下面節(jié)點(diǎn)
?配置代碼


1 <?xml version="1.0" encoding="utf-8"?> 2 <configuration> 3 <location path="." inheritInChildApplications="false"> 4 <system.webServer> 5 <handlers> 6 <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> 7 </handlers> 8 <aspNetCore processPath="dotnet" arguments=".\MesErp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" > 9 <environmentVariables> 10 <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> 11 </environmentVariables> 12 </aspNetCore> 13 </system.webServer> 14 </location> 15 </configuration> 16 <!--ProjectGuid: f7e462b4-210d-455c-b73f-b1a6fcbfb0a8-->
運(yùn)行webapi
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-437242.html
?
到了這里,關(guān)于WEB API .NET環(huán)境發(fā)布的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!