Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.net中作为服务引用的SOAP服务_C#_Wcf_Web Services_Soap_Visual Studio 2013 - Fatal编程技术网

C# 在.net中作为服务引用的SOAP服务

C# 在.net中作为服务引用的SOAP服务,c#,wcf,web-services,soap,visual-studio-2013,C#,Wcf,Web Services,Soap,Visual Studio 2013,在我的项目中,我有两个SOAP服务引用,它已经很好地工作了一段时间,但今天我在两个服务上都做了“更新服务引用”,因为我已经对它们进行了更新。 但是现在这些方法的数据结构已经发生了很大的变化,我不知道如何将其改变回去 关于我的方法“bookFlight”,以参数BookModel为例 public class BookModel { /// <summary> /// Id /// </summary> public int Id { get

在我的项目中,我有两个SOAP服务引用,它已经很好地工作了一段时间,但今天我在两个服务上都做了“更新服务引用”,因为我已经对它们进行了更新。 但是现在这些方法的数据结构已经发生了很大的变化,我不知道如何将其改变回去

关于我的方法“bookFlight”,以参数BookModel为例

public class BookModel
{
    /// <summary>
    /// Id
    /// </summary>
    public int Id { get; set; }
    /// <summary>
    /// Credit card informaiton
    /// </summary>
    public CreditCardInfoModel CreditCard { get; set; }
}
但在我更新了我的服务之后,我现在是否必须按如下方式调用它:

mySoapClient.bookFlight(new bookFlightRequest()
{
    Body = new bookFlightRequestBody(new BookModel()
    {
        ...
    })
});
我该怎么做才能让它回到第一个示例中的原始数据结构

可以在以下位置找到soap:

我的服务参考设置:

如果需要SOAP代码

/// <summary>
    /// Summary description for LameDuck
    /// </summary>
    [WebService(Namespace = "http://02267.dtu.sogaard.us/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class LameDuck : System.Web.Services.WebService
    {
        private Context context;
        private BankPortTypeClient bankService;
        private int groupNumber;
        private accountType account;

        public LameDuck()
        {
            context = new Context();
            bankService = new BankPortTypeClient();
            groupNumber = int.Parse(WebConfigurationManager.AppSettings["GroupNumber"]);
            account = new accountType()
            {
                number = "50208812",
                name = "LameDuck"
            };
        }

        /// <summary>
        /// Book a flight
        /// </summary>
        /// <param name="model">Booking data</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <exception cref="CreditCardValidationFailedException">Credit card validation failed</exception>
        /// <exception cref="CreditCardChargeFailedException">Charging the credit card failed</exception>
        /// <returns>True or exception</returns>
        [WebMethod]
        public bool bookFlight(BookModel model)
        {
            var flight = context.Flights.Where(x => x.Id == model.Id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(model.Id.ToString());

            if (!bankService.validateCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price))
                throw new CreditCardValidationFailedException();

            if (!bankService.chargeCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price, account))
                throw new CreditCardChargeFailedException();

            return true;
        }

        /// <summary>
        /// Search for flights
        /// </summary>
        /// <param name="model">Search data</param>
        /// <returns>List of flights, may be empty</returns>
        [WebMethod]
        public List<Flight> getFlights(SearchFlightModel model)
        {
            var select = context.Flights.Select(x => x);

            if (model.DestinationLocation != null)
                select = select.Where(x => x.Info.DestinationLocation == model.DestinationLocation);
            if (model.DepartureLocation != null)
                select = select.Where(x => x.Info.DepartureLocation == model.DepartureLocation);
            if (model.Date != null)
                select = select.Where(x => x.Info.DepartueTime.Date == model.Date.Date);

            return select.ToList();
        }

        /// <summary>
        /// Cancel a flight
        /// </summary>
        /// <param name="model">Cancel data</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <exception cref="UnableToRefundException">If unable to refund the flight to the credit card</exception>
        /// <returns>True or exception</returns>
        [WebMethod]
        public bool cancelFlight(CancelModel model)
        {
            var flight = context.Flights.Where(x => x.Id == model.Id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(model.Id.ToString());

            if (!bankService.refundCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price, account))
                throw new UnableToRefundException();

            return true;
        }

        /// <summary>
        /// Get a flight by id
        /// </summary>
        /// <param name="id">flight id</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <returns>The flight</returns>
        [WebMethod]
        public Flight getFlight(int id)
        {
            var flight = context.Flights.Where(x => x.Id == id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(id.ToString());
            return flight;
        }

        /// <summary>
        /// Reset the database
        /// 
        /// This is only to be used for testing
        /// </summary>
        [WebMethod]
        public void ResetDatabase()
        {
            // Remove all flights
            foreach (var flight in context.Flights)
                context.Flights.Remove(flight);
            context.SaveChanges();

            // Add Flights
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 350,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Spain",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 350,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Spain",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(2),
                    ArrivalTime = DateTime.UtcNow.AddDays(2).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 450,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Italy",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 450,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Italy",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 650,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Turkey",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 2"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 650,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Turkey",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 2"
                }
            });
            context.SaveChanges();
        }
    }
//
///跛脚鸭概述
/// 
[WebService(命名空间=”http://02267.dtu.sogaard.us/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
//[System.Web.Script.Services.ScriptService]
公共类:System.Web.Services.WebService
{
私人语境;
私人银行端口类型客户银行服务;
私有整数组号;
私人账户类型账户;
公营机构(
{
上下文=新上下文();
bankService=新的BankPortTypeClient();
groupNumber=int.Parse(WebConfiguration Manager.AppSettings[“groupNumber”]);
account=新accountType()
{
number=“50208812”,
name=“跛脚鸭”
};
}
/// 
///预订航班
/// 
///预订数据
///如果找不到航班
///信用卡验证失败
///向信用卡充值失败
///正确还是例外
[网络方法]
公共图书馆图书航班(图书模型)
{
var flight=context.Flights.Where(x=>x.Id==model.Id).FirstOrDefault();
如果(航班==null)
抛出新的FlightNotFoundException(model.Id.ToString());
如果(!bankService.validateCreditCard(组号,新CreditCardInfo类型)()
{
name=model.CreditCard.name,
编号=model.CreditCard.number,
expirationDate=新的expirationDateType()
{
年份=model.CreditCard.ExpirationDate.year,
月份=model.CreditCard.ExpirationDate.month
}
}、航班、价格)
抛出新的CreditCardValidationFailedException();
如果(!bankService.chargeCreditCard(组号,新CreditCardInfo类型)()
{
name=model.CreditCard.name,
编号=model.CreditCard.number,
expirationDate=新的expirationDateType()
{
年份=model.CreditCard.ExpirationDate.year,
月份=model.CreditCard.ExpirationDate.month
}
},航班,价格,账目)
抛出新的CreditCardChargeFailedException();
返回true;
}
/// 
///搜寻航班
/// 
///搜索数据
///航班列表,可能为空
[网络方法]
公共列表getFlights(SearchFlightModel)
{
var select=context.Flights.select(x=>x);
if(model.DestinationLocation!=null)
select=select.Where(x=>x.Info.DestinationLocation==model.DestinationLocation);
if(model.DepartureLocation!=null)
select=select.Where(x=>x.Info.DepartureLocation==model.DepartureLocation);
如果(model.Date!=null)
select=select.Where(x=>x.Info.DepartueTime.Date==model.Date.Date);
返回select.ToList();
}
/// 
///取消航班
/// 
///取消数据
///如果找不到航班
///如果无法将航班退款至信用卡
///正确还是例外
[网络方法]
公共bool取消航班(取消机型)
{
var flight=context.Flights.Where(x=>x.Id==model.Id).FirstOrDefault();
如果(航班==null)
抛出新的FlightNotFoundException(model.Id.ToString());
如果(!bankService.returnCreditCard(组号,新CreditCardInfo类型)()
{
name=model.CreditCard.name,
编号=model.CreditCard.number,
expirationDate=新的expirationDateType()
{
年份=model.CreditCard.ExpirationDate.year,
月份=model.CreditCard.ExpirationDate.month
}
},航班,价格,账目)
抛出新的UnableToRefundException();
返回true;
}
/// 
///凭身份证坐飞机
/// 
///航班号
///如果找不到航班
///航班
[网络方法]
公共航班(国际id)
{
var flight=context.Flights.Where(x=>x.Id==Id).FirstOrDefault();
如果(航班==null)
抛出新的FlightNotFoundException(id.ToString());
返程航班;
/// <summary>
    /// Summary description for LameDuck
    /// </summary>
    [WebService(Namespace = "http://02267.dtu.sogaard.us/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class LameDuck : System.Web.Services.WebService
    {
        private Context context;
        private BankPortTypeClient bankService;
        private int groupNumber;
        private accountType account;

        public LameDuck()
        {
            context = new Context();
            bankService = new BankPortTypeClient();
            groupNumber = int.Parse(WebConfigurationManager.AppSettings["GroupNumber"]);
            account = new accountType()
            {
                number = "50208812",
                name = "LameDuck"
            };
        }

        /// <summary>
        /// Book a flight
        /// </summary>
        /// <param name="model">Booking data</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <exception cref="CreditCardValidationFailedException">Credit card validation failed</exception>
        /// <exception cref="CreditCardChargeFailedException">Charging the credit card failed</exception>
        /// <returns>True or exception</returns>
        [WebMethod]
        public bool bookFlight(BookModel model)
        {
            var flight = context.Flights.Where(x => x.Id == model.Id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(model.Id.ToString());

            if (!bankService.validateCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price))
                throw new CreditCardValidationFailedException();

            if (!bankService.chargeCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price, account))
                throw new CreditCardChargeFailedException();

            return true;
        }

        /// <summary>
        /// Search for flights
        /// </summary>
        /// <param name="model">Search data</param>
        /// <returns>List of flights, may be empty</returns>
        [WebMethod]
        public List<Flight> getFlights(SearchFlightModel model)
        {
            var select = context.Flights.Select(x => x);

            if (model.DestinationLocation != null)
                select = select.Where(x => x.Info.DestinationLocation == model.DestinationLocation);
            if (model.DepartureLocation != null)
                select = select.Where(x => x.Info.DepartureLocation == model.DepartureLocation);
            if (model.Date != null)
                select = select.Where(x => x.Info.DepartueTime.Date == model.Date.Date);

            return select.ToList();
        }

        /// <summary>
        /// Cancel a flight
        /// </summary>
        /// <param name="model">Cancel data</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <exception cref="UnableToRefundException">If unable to refund the flight to the credit card</exception>
        /// <returns>True or exception</returns>
        [WebMethod]
        public bool cancelFlight(CancelModel model)
        {
            var flight = context.Flights.Where(x => x.Id == model.Id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(model.Id.ToString());

            if (!bankService.refundCreditCard(groupNumber, new creditCardInfoType()
                                {
                                    name = model.CreditCard.Name,
                                    number = model.CreditCard.Number,
                                    expirationDate = new expirationDateType()
                                    {
                                        year = model.CreditCard.ExpirationDate.Year,
                                        month = model.CreditCard.ExpirationDate.Month
                                    }
                                }, flight.Price, account))
                throw new UnableToRefundException();

            return true;
        }

        /// <summary>
        /// Get a flight by id
        /// </summary>
        /// <param name="id">flight id</param>
        /// <exception cref="FlightNotFoundException">If the flight was not found</exception>
        /// <returns>The flight</returns>
        [WebMethod]
        public Flight getFlight(int id)
        {
            var flight = context.Flights.Where(x => x.Id == id).FirstOrDefault();
            if (flight == null)
                throw new FlightNotFoundException(id.ToString());
            return flight;
        }

        /// <summary>
        /// Reset the database
        /// 
        /// This is only to be used for testing
        /// </summary>
        [WebMethod]
        public void ResetDatabase()
        {
            // Remove all flights
            foreach (var flight in context.Flights)
                context.Flights.Remove(flight);
            context.SaveChanges();

            // Add Flights
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 350,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Spain",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 350,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Spain",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(2),
                    ArrivalTime = DateTime.UtcNow.AddDays(2).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 450,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Italy",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 450,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Italy",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 1"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 650,
                Info = new FlightInfo()
                {
                    DepartureLocation = "DTU",
                    DestinationLocation = "Turkey",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 2"
                }
            });
            context.Flights.Add(new Flight()
            {
                Airline = "DTU Airlines",
                Price = 650,
                Info = new FlightInfo()
                {
                    DepartureLocation = "Turkey",
                    DestinationLocation = "DTU",
                    DepartueTime = DateTime.UtcNow.AddDays(1),
                    ArrivalTime = DateTime.UtcNow.AddDays(1).AddHours(2),
                    Carrier = "Carrier 2"
                }
            });
            context.SaveChanges();
        }
    }