c#web服务不返回结果

时间:2012-11-19 03:19:24

标签: c# winforms web-services webmethod

我最近“完成”了一个新项目,除了一个小问题。我没有得到我的结果。

该项目通过SOAP客户端以及请求和响应类使用c#Web服务。该项目旨在预留一些东西,在这个演示中,它预留了一个电影院的座位。但是,当数据从Windows窗体客户端传递到Web服务时,不会返回任何内容。我最近在执行Web方法时冻结了项目冻结。

这是调用Web服务的方法(方法签名只是临时的)

public void derp()
{
    var client = new SampleServiceSoapClient();
    var req = new GetReservationRequest();
    req.row = row;
    req.seat = seat;
    req.name = textNameRequest.Text;
    try
    {
        client.GetReservation(req);
    }
    catch (Exception err)
    {
        MessageBox.Show("Server Unavailable");
    }
}

我在一个单独的线程上运行此方法以停止崩溃。该方法的输出应该通过响应对象返回,然后我将所述对象的值分配给表单上的文本框。但是,数据在返回之前就会丢失。

网络方法如下

[WebMethod]
public GetReservationResponse GetReservation(GetReservationRequest req)
{
    object o = HttpContext.Current.Cache["Reservation"];
    if(o == null)
    {
        o = reservedSeat;
    }
    else
    {
        reservedSeat = (bool[,])o;
    }

    GetReservationResponse resp = new GetReservationResponse();
    string rowHolder = "A";
    int rowRequest = req.row;
    int seatCopy = 0;

    bool emptySeat = false;
    while (rowRequest < 12)
    {
        for (int seat = req.seat; seat < 16; seat++)
        {
            if (reservedSeat[req.row, seat])
            {
             //Loop back
            }
            else
            {
                emptySeat = true;
                seatCopy = seat;
                break;
            }
        }
        if (reservedSeat[req.row, 15])
        {
            seatCopy = 0;
            break;
        }
    }
    switch (rowRequest)
    {
        case 1: rowHolder = "A";
            break;
        case 2: rowHolder = "B";
            break;
        case 3: rowHolder = "C";
            break;
        case 4: rowHolder = "D";
            break;
        case 5: rowHolder = "E";
            break;
        case 6: rowHolder = "F";
            break;
        case 7: rowHolder = "G";
            break;
        case 8: rowHolder = "H";
            break;
        case 9: rowHolder = "I";
            break;
        case 10: rowHolder = "J";
            break;
        case 11: rowHolder = "K";
            break;
        case 12: rowHolder = "L";
            break;
        default: rowHolder = "None Specified";
            break;
    }
    int x = 0;
    if (!reservedSeat[rowRequest, seatCopy])
    {
        reservedSeat[rowRequest, seatCopy] = true;
        seatCopy++;
        //resp.row = rowRequest;
        x = seatCopy;
        seatCopy--;
        if (seatCopy.Equals(15))
        {
            rowRequest++;
        }
    }
    resp.row = rowHolder;
    resp.seat = x;   
    //row++            
    return resp;
}

我不知道为什么数据在返回之前就会丢失,但有些信息会很惊人......

1 个答案:

答案 0 :(得分:0)

此代码中rowrequest的位置是递增的吗?在我看来,你在这里有无限循环:

        while (rowRequest < 12)
        {
                for (int seat = req.seat; seat < 16; seat++)
                {
                    if (reservedSeat[req.row, seat])
                    {
                    //Loop back
                    }
                    else
                    {
                        emptySeat = true;
                        seatCopy = seat;
                        break;
                    }
            }
            if (reservedSeat[req.row, 15])
            {
                seatCopy = 0;
                break;
            }
        }