"Visual Studio> 서비스 참조"를 사용하여 wcf 서비스의 프록시 클래스를 생성했으며 서비스에 연결할 수 있습니다. 서비스 연산 중 하나가 항목 목록을 나타내는 압축 문자열을 byte []로 반환합니다.XmlSerializer를 사용하여 객체 목록을 역 직렬화 할 수 없습니다
문제점 : 바이트 [], i가 직렬화 된 바이트 []에서 XML을 얻을 수있는 압축 해제 할 수 있지만 객체 직렬화 수없는 내가 빈 값 오브젝트의리스트를 얻을. 여기
내가
<?xml version="1.0"?>
<ArrayOfItem xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Item>
...
<FieldX>
..
</FieldX>
</Item>
</ArrayOfItem>
ArrayOfItem 압축 해제에서 얻으 XML 문자열은 클래스하지 ...하지만 항목은 다음과 같습니다
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://company.com/")]
public partial class Item: BaseObjectModel {
private bool FieldX;
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public bool FieldX{
get {
return this.FieldX;
}
set {
this.FieldX= value;
this.RaisePropertyChanged("FieldX");
}
}
}
내 코드
List<Item> lista = null;
MemoryStream InStream = new MemoryStream(byteData);
GZipStream gzDecompressed = new GZipStream(InStream, CompressionMode.Decompress, true);
MemoryStream OutStream = new MemoryStream();
//Retrieve the size of the decompressed file from the compressed footer
byte[] bufferWrite = new byte[4];
InStream.Position = (int)InStream.Length - 4;
InStream.Read(bufferWrite, 0, 4);
InStream.Position = 0;
//Convert to int for using in declaring our Byte[] size
int bufferLength = BitConverter.ToInt32(bufferWrite, 0);
//1MB Buffer
byte[] buffer = new byte[1024 * 1024];
while (true)
{
int bytesRead = gzDecompressed.Read(buffer, 0, buffer.Length);
// If we reached the end of the data
if (bytesRead == 0) break;
OutStream.Write(buffer, 0, bytesRead);
}
// Close the streams
InStream.Close();
gzDecompressed.Close();
OutStream.Position = 0;
var sr = new StreamReader(OutStream);
string myStr = sr.ReadToEnd();
OutStream.Position = 0;
XmlSerializer serializer = new XmlSerializer(typeof(List<Item>));
XmlReader read = XmlReader.Create(OutStream);
List<Item> lista2 = (List<Item>)serializer.Deserialize(read);
문자열 그것은 서비스가 제공하는 것을 보는 것일 뿐이며, 메모리 스트림을 사용하여 비 직렬화합니다.
나는 항목의 오른쪽 번호 목록을 얻을 수 있지만, 모든 항목은
어떤 도움에 감사드립니다 .... 덕분에 빈 속성이 있습니다.
EDIT
나는 프록시의 항목 객체를 이용하여 목록을 직렬화 시도 난 XML은
서비스
<?xml version="1.0"?><ArrayOfItem xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Item>...
직렬화는 XML에서 XML 인코딩이 다른 것을 알 나
<?xml version="1.0" encoding="utf-16"?><ArrayOfItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Item xmls="company.com">
좋아, 내가 그랬어, 내가 게시물을 업데이 트 했어. – Alessandro