好的,按一下按钮,我的代码应该将系泊增加一,直到它达到五,在它达到五之后,它必须将码头增加一,然后系泊增加一直到它达到五和然后将码头增加一,依此类推。
但它目前所做的是,它将码头增加,然后系泊增加至 5,但在我单击按钮使其再次增加之后(它应该将码头增加至 2 并将系泊回增加至 1)它崩溃了。
这是我的代码
//Setting the max value for Piers and Moorings
public const int maxPiers = 6;
public const int maxMoorings = 30;
private static bool[,] reserveMooring = new bool[maxPiers, maxMoorings];
[WebMethod]
public BoatResponse ReserveMooring(BoatRequest req)
{
var res = new BoatResponse();
//if mooringCalc set to 0, if smaller than maxMoorings increment
for (int mooringCalc = 0; mooringCalc < maxMoorings; mooringCalc++)
{
//if pierCalc set to 0, if smaller than maxPiers increment
for (int pierCalc = 0; pierCalc < maxMoorings / maxPiers; mooringCalc++)
{
if (!reserveMooring[pierCalc, mooringCalc])
{
reserveMooring[pierCalc, mooringCalc] = true;
res.Pier = (Pier)pierCalc;
res.Mooring = (Mooring)mooringCalc;
return res;
}
}
}
return null;
}
崩溃发生在这里:
private void button1_Click(object sender, EventArgs e)
{
var req = new BoatRequest();
req.Name = txtName.Text;
var client = new BoatReserveSoapClient();
BoatResponse response = client.ReserveMooring(req);//error is on this line
这是BoatResponse
namespace NewBoatBookingApp
{
public enum Pier
{
one,
two,
three,
four,
five,
six
}
public enum Mooring
{
one,
two,
three,
four,
five
}
public class BoatResponse
{
public Pier Pier;
public Mooring Mooring;
}
}
这是错误:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Instance validation error: '6' is not a valid value for NewBoatBookingApp.Mooring.