C# Soap序列化程序不支持序列化泛型类型
我在尝试在C#类中创建soap消息时遇到错误 预订课程-C# Soap序列化程序不支持序列化泛型类型,c#,generics,serialization,soap,C#,Generics,Serialization,Soap,我在尝试在C#类中创建soap消息时遇到错误 预订课程- public class GuestDetails { public string GuestTitle { get; set; } public string GuestName { get; set; } public string Address1 { get; set; } public string Address2 { get; set; }
public class GuestDetails
{
public string GuestTitle { get; set; }
public string GuestName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string Pincode { get; set; }
public string Country { get; set; }
public string Nationality { get; set; }
public string EmailId { get; set; }
public string PhoneNo { get; set; }
}
public class BookingDetails
{
public string BookingNumber { get; set; }
public string BookingDate { get; set; }
public string Bookedby { get; set; }
public string OTAId { get; set; }
public string OTAName { get; set; }
public string BookingStatus { get; set; }
public string CheckinDate { get; set; }
public string CheckinTime { get; set; }
public string CheckoutDate { get; set; }
public string CheckoutTime { get; set; }
}
public class RoomingDetail
{
public string RoomTypeId { get; set; }
public string RateId { get; set; }
public string NoOfRooms { get; set; }
public string Adult { get; set; }
public string Children { get; set; }
public string NoOfExtrabed { get; set; }
public string MealPlan { get; set; }
}
public class Hotel
{
public string hotelid { get; set; }
public GuestDetails GuestDetails { get; set; }
public BookingDetails BookingDetails { get; set; }
public List<RoomingDetail> RoomingDetails { get; set; }
}
[Serializable]
public class RootObject
{
public string accessKey { get; set; }
public string channelId { get; set; }
public List<Hotel> hotels { get; set; }
}
public class GuestDetails
{
公共字符串GuestTitle{get;set;}
公共字符串GuestName{get;set;}
公共字符串地址1{get;set;}
公共字符串地址2{get;set;}
公共字符串地址3{get;set;}
公共字符串Pincode{get;set;}
公共字符串国家{get;set;}
公共字符串{get;set;}
公共字符串EmailId{get;set;}
公共字符串PhoneNo{get;set;}
}
公共课预订详情
{
公共字符串BookingNumber{get;set;}
公共字符串BookingDate{get;set;}
公共字符串Bookedby{get;set;}
公共字符串OTAId{get;set;}
公共字符串名称{get;set;}
公共字符串BookingStatus{get;set;}
公共字符串CheckinDate{get;set;}
公共字符串检查时间{get;set;}
公共字符串签出日期{get;set;}
公共字符串签出时间{get;set;}
}
公共教室详细信息
{
公共字符串RoomTypeId{get;set;}
公共字符串RateId{get;set;}
公共字符串noofroms{get;set;}
公共字符串{get;set;}
公共字符串子项{get;set;}
公共字符串NoOfExtrabed{get;set;}
公共字符串MealPlan{get;set;}
}
公务舱酒店
{
公共字符串hotelid{get;set;}
公共GuestDetails GuestDetails{get;set;}
公共BookingDetails BookingDetails{get;set;}
公共列表RoomingDetails{get;set;}
}
[可序列化]
公共类根对象
{
公共字符串accessKey{get;set;}
公共字符串channelId{get;set;}
公共列表酒店{get;set;}
}
将C#类转换为Soap-
RootObject R = new RootObject();
R.accessKey = "";
R.channelId = "";
R.hotels = new List<Hotel>();
Hotel _hotel = new Hotel();
_hotel.hotelid = "3";
_hotel.GuestDetails = new GuestDetails();
_hotel.GuestDetails.GuestName = "GuestName";
_hotel.GuestDetails.GuestTitle = "GuestTitle";
_hotel.GuestDetails.Nationality = "Nationality";
_hotel.GuestDetails.PhoneNo = "PhoneNo";
_hotel.GuestDetails.Pincode = "Pincode";
_hotel.GuestDetails.Address1 = "Address1";
_hotel.GuestDetails.Address2 = "Address2";
_hotel.GuestDetails.Address3 = "Address3";
_hotel.GuestDetails.Country = "Country";
_hotel.GuestDetails.EmailId = "EmailId";
_hotel.RoomingDetails = new List<RoomingDetail>();
RoomingDetail _roomingDetails = new RoomingDetail();
_roomingDetails.Adult = "1";
_roomingDetails.Children = "2";
_roomingDetails.MealPlan = "sds";
_roomingDetails.NoOfExtrabed = "";
_roomingDetails.NoOfRooms = "1";
_roomingDetails.RateId = "222";
_roomingDetails.RoomTypeId = "11";
_hotel.RoomingDetails.Add(_roomingDetails);
_hotel.BookingDetails = new BookingDetails();
//BookingDetails _bookingDetails = new BookingDetails();
_hotel.BookingDetails.Bookedby = "Jagadees";
_hotel.BookingDetails.BookingDate = "05-08-2014";
_hotel.BookingDetails.BookingNumber = "15999";
_hotel.BookingDetails.BookingStatus = "Success";
_hotel.BookingDetails.CheckinDate = "03-09-2014";
_hotel.BookingDetails.CheckinTime = "";
_hotel.BookingDetails.CheckoutDate = "05-09-2014";
_hotel.BookingDetails.CheckoutTime = "";
_hotel.BookingDetails.OTAId = "";
_hotel.BookingDetails.OTAName = "";
R.hotels.Add(_hotel);
var r = new Random();
SoapFormatter formatter = new SoapFormatter();
string myTempFile = Path.Combine(Path.GetTempPath(), r.Next() + "SaveFile.txt");
GC.SuppressFinalize(myTempFile);
Stream objfilestream = new FileStream(myTempFile, FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(objfilestream, R); <-- ERROR HERE -->
objfilestream.Close();
rootobjectr=newrootobject();
R.accessKey=“”;
R.channelId=“”;
R.hotels=新列表();
酒店=新酒店();
_hotelid=“3”;
_hotel.GuestDetails=新的GuestDetails();
_hotel.GuestDetails.GuestName=“GuestName”;
_hotel.GuestDetails.GuestTitle=“GuestTitle”;
_hotel.GuestDetails.national=“national”;
_hotel.GuestDetails.PhoneNo=“PhoneNo”;
_hotel.GuestDetails.Pincode=“Pincode”;
_hotel.GuestDetails.Address1=“Address1”;
_hotel.GuestDetails.Address2=“Address2”;
_hotel.GuestDetails.Address3=“Address3”;
_hotel.GuestDetails.Country=“Country”;
_hotel.GuestDetails.EmailId=“EmailId”;
_hotel.RoomingDetails=新列表();
RoomingDetail _roomingDetails=新RoomingDetail();
_roomingDetails.成人=“1”;
_roomingDetails.Children=“2”;
_roomingDetails.MealPlan=“sds”;
_roomingDetails.NoOfExtrabed=“”;
_roomingDetails.noofroms=“1”;
_roomingDetails.RateId=“222”;
_roomingDetails.RoomTypeId=“11”;
_hotel.RoomingDetails.Add(_RoomingDetails);
_hotel.BookingDetails=新的BookingDetails();
//BookingDetails _BookingDetails=新的BookingDetails();
_hotel.BookingDetails.Bookedby=“Jagadees”;
_hotel.BookingDetails.BookingDate=“05-08-2014”;
_hotel.BookingDetails.BookingNumber=“15999”;
_hotel.BookingDetails.BookingStatus=“成功”;
_hotel.BookingDetails.CheckinDate=“03-09-2014”;
_hotel.BookingDetails.CheckinTime=“”;
_hotel.BookingDetails.CheckoutDate=“05-09-2014”;
_hotel.BookingDetails.CheckoutTime=“”;
_hotel.BookingDetails.OTAId=“”;
_hotel.BookingDetails.OTAName=“”;
R.hotels.Add(_hotel);
var r=新的随机变量();
SoapFormatter formatter=新的SoapFormatter();
字符串myTempFile=Path.Combine(Path.GetTempPath(),r.Next()+“SaveFile.txt”);
GC.SuppressFinalize(myTempFile);
Stream objfilestream=newfilestream(myTempFile,FileMode.Create,FileAccess.Write,FileShare.None);
序列化(objfilestream,R);
objfilestream.Close();
错误-
public class GuestDetails
{
public string GuestTitle { get; set; }
public string GuestName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string Pincode { get; set; }
public string Country { get; set; }
public string Nationality { get; set; }
public string EmailId { get; set; }
public string PhoneNo { get; set; }
}
public class BookingDetails
{
public string BookingNumber { get; set; }
public string BookingDate { get; set; }
public string Bookedby { get; set; }
public string OTAId { get; set; }
public string OTAName { get; set; }
public string BookingStatus { get; set; }
public string CheckinDate { get; set; }
public string CheckinTime { get; set; }
public string CheckoutDate { get; set; }
public string CheckoutTime { get; set; }
}
public class RoomingDetail
{
public string RoomTypeId { get; set; }
public string RateId { get; set; }
public string NoOfRooms { get; set; }
public string Adult { get; set; }
public string Children { get; set; }
public string NoOfExtrabed { get; set; }
public string MealPlan { get; set; }
}
public class Hotel
{
public string hotelid { get; set; }
public GuestDetails GuestDetails { get; set; }
public BookingDetails BookingDetails { get; set; }
public List<RoomingDetail> RoomingDetails { get; set; }
}
[Serializable]
public class RootObject
{
public string accessKey { get; set; }
public string channelId { get; set; }
public List<Hotel> hotels { get; set; }
}
用户代码未处理SerializationException
Soap序列化程序不支持序列化泛型类型:
System.Collections.Generic.List`1[SoapwApp.Hotel]
如果它不支持将列表更改为数组,您可能需要自己序列化它。例如:在RoomingDetails[]RoomingDetails中列出RoomingDetails。你有没有想过在类中使用
[Serializable]
。。?确保这也在您的使用中使用System.Runtime.Serialization.Formatters.Soap我想是的。我在检查所有可能性后手动序列化。@vajura@bit我已尝试使用数组,。但是肥皂还没有完全洗好。