.NET中的SOAP服务即服务参考

仙女座

我的项目中有2个SOAP服务参考,并且已经运行了一段时间,但是今天我对两个服务都进行了“ Update Service Refrence”,因为我已经对它们进行了更新。但是现在这些方法的数据结构已经发生了很大的变化,我不知道如何将其改回来。

在我的方法“ bookFlight”中,以参数BookModel为例。

public class BookModel
{
    /// <summary>
    /// Id
    /// </summary>
    public int Id { get; set; }
    /// <summary>
    /// Credit card informaiton
    /// </summary>
    public CreditCardInfoModel CreditCard { get; set; }
}

在我只需要执行以下操作以调用SOAP methoid之前

mySoapClient.bookFlight(new BookModel() { ... });

但是,在更新服务后,我现在必须像以下这样调用它:

mySoapClient.bookFlight(new bookFlightRequest()
{
    Body = new bookFlightRequestBody(new BookModel()
    {
        ...
    })
});

我该怎么做才能使它从第一个示例回到原始数据结构?

肥皂可以在这里找到:http: //02267.dtu.sogaard.us/LameDuck.asmx

我的服务参考设置: 在此处输入图片说明

如果需要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();
        }
    }

解决方案设置: 在此处输入图片说明

提姆

.ASMX是旧版Web服务(在Microsoft技术堆栈中)。通过Visual Studio将服务引用添加到旧版Web服务时,可以单击“服务引用设置”对话框中的“高级”按钮,然后单击“添加网络引用...”按钮以进行添加。

在此处输入图片说明

在此处输入图片说明

我不确定为什么突然需要它,但是我想不到的是,对于.ASMX,生成代理的代码很可能与WCF不同。另一个选择是,如果您更改了绑定(我相信basicHttpBinding是唯一支持.ASMX-SOAP 1.1的绑定-除非您使用自定义绑定)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用WSDL在.NET中创建了SOAP服务参考。代理类似乎没有公开SOAP响应

来自分类Dev

.NET服务参考-Soap客户端状态始终为错误

来自分类Dev

Web服务中的参考控件?

来自分类Dev

接受ASP.NET Web服务中的SOAP请求

来自分类Dev

如何在ASP.NET中调用SOAP服务

来自分类Dev

iOS中的SOAP Web服务

来自分类Dev

在SWIFT中调用SOAP服务

来自分类Dev

Spring Boot 中的 SOAP 服务

来自分类Dev

.Net生成服务类型为“系统”的服务参考

来自分类Dev

使用.net消费Saber Soap服务

来自分类Dev

什么是容器即服务

来自分类Dev

运行libreoffice即服务

来自分类Dev

Tomcat即服务

来自分类Dev

更改代码中的服务参考URL

来自分类Dev

Windows服务中的参考错误

来自分类Dev

在工作流服务中添加服务参考地址

来自分类Dev

无法从Magento 2 SOAP API反序列化SOAP响应-响应中的XML命名空间与服务参考WSDL之间不匹配

来自分类Dev

在ASP.Net MVC中添加WCF服务参考时出错

来自分类Dev

Visual Studio 2012中的SOAP服务

来自分类Dev

WSDL中的SOAP Web服务端点

来自分类Dev

PHP中的SOAP服务器错误?

来自分类Dev

带有SOAP的PHP中的Web服务

来自分类Dev

Visual Studio 2012中的SOAP服务

来自分类Dev

参数在SOAP服务中传递NULL值

来自分类Dev

从Soap服务的响应中获取空值

来自分类Dev

WSDL中的SOAP Web服务端点

来自分类Dev

在Yii框架中调用SOAP服务

来自分类Dev

soap ui调用.net soap服务成功,但在ksoap2 android中失败,并显示http 500

来自分类Dev

soap ui调用.net soap服务成功,但在ksoap2 android中失败,并显示http 500