【发布时间】:2019-05-29 12:48:09
【问题描述】:
我有这个 c# 代码,我试图从 Visual Studio 中的 wsdl 获取数据。 代码没问题,但是当我尝试将数据写入记事本时,它只显示一个空白区域:
WindowsService1.ServiceReference1.GetModifiedBookingsOperationResponse getModbkgsResp;
using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
int noofBookings = 1;
getModbkgsResp = proxy.GetModifiedBookings(getModBkgsReq);
WindowsService1.ServiceReference1.Booking[] bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = bookings;
if (getModbkgsResp.Bookings != null)
{
for (int i = 0; i < bookings.Length; i++)
{
Booking bk = new WindowsService1.ServiceReference1.Booking();
getModbkgsResp.Bookings[i] = bk;
if (bk != null )
{
bookingSource = bk.BookingSource;
if (bk.BookingId == Bookingcode)
{
this.WriteToFile("Booking Source =" + bookingSource + "");
}
else
{
this.WriteToFile("Sorry could not find your source of booking");
}
}
else
{
this.WriteToFile("Looks like source is null " );
}
}
}
else
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
}
}
【问题讨论】:
-
您是否尝试过设置断点并单步执行代码?您认为显示
WriteToFile的定义可能很重要吗?如果问题与无法写入文件的内容有关,在我看来,查看写入文件的实际代码很重要。 -
您似乎在调用
GetModifiedBookings,但随后用一个新数组覆盖了响应的Bookings数组。这背后的逻辑是什么?是的,当你这样做时,它们都将是空白的。 -
另外,你确认
bookings.Length大于0了吗? -
@JasonBoyd 下面是 writetoFile 的代码: private void WriteToFile(string text) { string path = "C:\\ServiceLog.txt";使用 (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }
-
@JohnWu OK 会尝试修改它并就结果提出建议
标签: c# asp.net web-services wsdl