我在我的項目中有2個SOAP服務引用,並且它已經很好地工作了一段時間,但是今天我在我的服務上做了一個「更新服務引用」,因爲我做了一個更新他們。 但是現在這些方法的數據結構已經發生了很大的變化,我無法弄清楚如何改回它。SOAP服務作爲服務參考.net
對我的方法「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
我的服務引用設置:如果需要
肥皂代碼?
/// <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();
}
}
解決方案的設置:
你有像TFS,git或svn這樣的sourcontrol嗎?或者你是否拿過任一應用的原始源代碼副本? – Kyle
@凱爾對不起,不知道這是爲什麼?但我自己製作了SOAP。第一篇文章中的「解決方案設置」。 – Androme
似乎在上次更新引用時,SOAP服務代理已將「SoapDocumentMethod.SoapParameterStyle」從「裸」更改爲「打包」。 –