내 안드로이드 기기에서 내 .net 프로젝트의 데이터를 가져 오려고합니다. android에서 데이터 전송
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://192.168.0.100/protobufnet/Default.aspx");
HttpResponse response;
response = client.execute(request);
DataPacket.Data data = DataPacket.Data.parseFrom(response.getEntity().getContent());
DataPacket.Data
내가 손으로 쓴이message Data {
required int32 Status = 1;
message Building {
required string Id = 1;
optional string Name = 2;
optional string Description = 3;
message RentSpace {
required string Id = 1;
optional string Name = 2;
optional string Description = 3;
message Year {
required int32 Year = 1;
message Item {
required string Id = 1;
optional string Name = 2;
optional string Description = 3;
optional string FunctionDescription = 4;
required bool Marked = 5;
required bool Remark = 6;
required bool SelfLearning = 7;
optional string Comment = 8;
repeated bool ActiveMonths = 9 [packed=true];
}
repeated Item Items = 2;
}
repeated Year Years = 4;
}
repeated RentSpace RentSpaces = 4;
}
repeated Building Buildings = 4;
}
처럼 보이는 내 .proto 파일에서 자동 생성되었습니다 안드로이드에 은이 코드를 사용하고이제이 .proto 파일에 대해 .net 프로젝트의 유효성을 검사하는 방법을 모릅니다. 따라서 다음과 같이 가정합니다.
[ProtoContract]
public class DataPacket
{
[ProtoMember(1)]
public int Status { get; set; }
[ProtoMember(2)]
public List<Building> Buildings { get; set; }
}
[ProtoContract]
public class Building
{
[ProtoMember(1)]
public String Id {get;set;}
[ProtoMember(2)]
public String Name {get;set;}
[ProtoMember(3)]
public String Description {get;set;}
[ProtoMember(4)]
public List<RentSpace> RentSpaces { get; set; }
}
[ProtoContract]
public class RentSpace
{
[ProtoMember(1)]
public String Id {get;set;}
[ProtoMember(2)]
public String Name {get;set;}
[ProtoMember(3)]
public String Description {get;set;}
[ProtoMember(4)]
public List<YearList> Years {get;set;}
}
[ProtoContract]
public class YearList
{
[ProtoMember(1)]
public int Year;
[ProtoMember(2)]
public List<ListItem> Items {get;set;}
}
[ProtoContract]
public class ListItem
{
[ProtoMember(1)]
public String Id {get;set;}
[ProtoMember(2)]
public String Name {get;set;}
[ProtoMember(3)]
public String Description {get;set;}
[ProtoMember(4)]
public String FunctionDescription { get; set; } //how to do the control
[ProtoMember(5)]
public bool Marked { get; set; }
[ProtoMember(6)]
public bool Remark { get; set; }
[ProtoMember(7)]
public bool SelfLearning { get; set; }
[ProtoMember(8)]
public string Comment { get; set; }
[ProtoMember(9)]
public bool[] ActiveMonths { get; set; }
하지만 작동하지 않습니다. 나는 .proto .net 네트워크 프로젝트가 사용하거나 내 .proto에 대해 유효성을 검사하도록한다.
답변 해 주셔서 감사합니다. proto 파일에서 VS 도구를 사용했는데 한 가지 예외가 있습니다.이 줄은 .proto의 "Building Buildings = 4; 오직 set 속성을 얻지 못합니다. 그래서 건물 목록을 설정할 수 없습니다. –
@Rickard 수집 속성이 get-only가되는 것은 꽤 보통입니다. 그냥/Add/Clear/AddRange 등을 가져 오거나 설정하려면 xslt를 편집 할 수 있습니다. –
수 년 동안 .net을 완료하지 못했지만 인식하지 못했습니다. , 다시 감사합니다. 얼마나 빨리 답장을 보내시겠습니까 :-) –