/// <summary> /// 获取航期 /// </summary> /// <param name="posDateParam"></param> /// <returns></returns> public static String GetShipListData(PosDateParam posDateParam, string allotType) { string result = ""; // 创建 HTTP 绑定对象 var binding = new BasicHttpBinding(); // 根据 WebService 的 URL 构建终端点对象 var endpoint = new EndpointAddress(System.Environment.GetEnvironmentVariable("PtsUrl")); // 创建调用接口的工厂,注意这里泛型只能传入接口 添加服务引用时生成的 webservice的接口 一般是 (XXXSoap) var factory = new ChannelFactory <pts.PtsServiceTJSoap>(binding, endpoint); // 从工厂获取具体的调用实例 var callClient = factory.CreateChannel(); //调用的对应webservice 服务类的函数生成对应的请求类Body (一般是webservice 中对应的方法+RequestBody 如GetInfoListRequestBody) pts.getShipListByPortRequestBody body = new pts.getShipListByPortRequestBody(); //以下是为该请求body添加对应的参数(就是调用webService中对应的方法的参数) body._posCode = Global.XCPOSCODE; body._dateFrom = posDateParam.dateFrom; body._dateTo = posDateParam.dateTo; body._port = posDateParam.port; body._allotType = allotType; body._his = false; //获取请求对象 (一般是webservice 中对应的方法+tRequest 如GetInfoListRequest) var request = new pts.getShipListByPortRequest(body); //发送请求 var v = callClient.getShipListByPortAsync(request); //异步等待 v.Wait(); //获取数据 result = v.Result.Body.getShipListByPortResult; return(result); }
/// <summary> /// 获取船计划 /// </summary> /// <param name="baseApi"></param> /// <returns></returns> public object Do_GetPlan(BaseApi baseApi) { PosDateParam posDateParam = JsonConvert.DeserializeObject <PosDateParam>(baseApi.param.ToString()); if (posDateParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } if (posDateParam.dateFrom == null || posDateParam.dateFrom == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } if (posDateParam.dateFrom.Length != 8) { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } ShipWeb obj = JsonConvert.DeserializeObject <ShipWeb>(GetShipListData(posDateParam, Global.XCALLOTTYPE)); Ship obj1 = new Ship(); obj1.date = posDateParam.dateFrom.Insert(4, "-").Insert(7, "-"); obj1.SHIPLIST = new List <SHIPLIST>(); if (obj.SHIPLIST != null) { foreach (var ship in obj.SHIPLIST) { bool ifNotPlan = true; for (int i = 0; i < obj1.SHIPLIST.Count; i++) { if (obj1.SHIPLIST[i].planId == ship.PLAN_ID) { try { Grade grade = new Grade(); grade.gradeId = ship.BUNK_GRADE_ID; grade.gradeName = ship.BUNK_GRADE_NAME; grade.ticketLeft = ship.TICKET_LEFT; grade.price = ship.PRICE; grade.halfPrice = ship.HALF_PRICE; obj1.SHIPLIST[i].gradeList.Add(grade); ifNotPlan = false; } catch (Exception) { } } } if (ifNotPlan) { SHIPLIST shipList = new SHIPLIST(); string[] ports = ship.SEAROUTE_NAME.Split("-"); if (ports.Length > 1) { shipList.fromPort = ports[0]; shipList.toPort = ports[1]; } try { string[] times = ship.SAILING_TIME.Split(":"); DateTime dtime = Convert.ToDateTime(ship.DEPARTURE_TIME); dtime = dtime.AddHours(Convert.ToInt16(times[0])); dtime = dtime.AddMinutes(Convert.ToInt16(times[1])); string sailing = ""; if (Convert.ToInt16(times[0]) != 0) { sailing = Convert.ToInt16(times[0]) + "小时"; } if (Convert.ToInt16(times[1]) != 0) { sailing += Convert.ToInt16(times[1]) + "分钟"; } shipList.arriveDate = dtime.ToString("yyyy-MM-dd"); shipList.arriveTime = dtime.ToString("HH:mm"); shipList.berthName = ship.BERTH_NAME; shipList.departureDate = Convert.ToDateTime(ship.DEPARTURE_TIME).ToString("yyyy-MM-dd"); shipList.departureTime = Convert.ToDateTime(ship.DEPARTURE_TIME).ToString("HH:mm"); shipList.planId = ship.PLAN_ID; shipList.sailingTime = sailing; shipList.searouteAlise = ship.SEAROUTE_ALISE; shipList.searouteName = ship.SEAROUTE_NAME; shipList.shipName = ship.SHIP_NAME; shipList.stu = ship.STU; shipList.voyageNumber = ship.VOYAGE_NUMBER; shipList.gradeList = new List <Grade>(); Grade grade = new Grade(); grade.gradeId = ship.BUNK_GRADE_ID; grade.gradeName = ship.BUNK_GRADE_NAME; grade.ticketLeft = ship.TICKET_LEFT; grade.price = ship.PRICE; grade.halfPrice = ship.HALF_PRICE; shipList.gradeList.Add(grade); obj1.SHIPLIST.Add(shipList); } catch (Exception) { } } } } return(obj1); }