나는, 부울, 오브젝트가 int와 같은 기본 유형을 포함 할 수 dictionary <string, object>
의 배열을 반환하는 등 노력하고 있어요 아니면 내가 그것을 얻을 수 있지만 그것은 dictionary<string, object>
.net4 WCF 사전에 포함 된 사전
의 또 다른 배열을 포함 할 수 사전에 사전이 존재한다면 비 직렬화하지 않을 것입니다.
Error in line 1 position 543. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data from a type that maps to the name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfArrayOfKeyValueOfstringanyType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ArrayOfArrayOfKeyValueOfstringanyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.
클래스 :
[DataContract(Namespace = "CISICPD")]
[KnownType(typeof(Dictionary<string,object>))]
public class TestResponse
{
[DataMember]
public Dictionary<string,object>[] Results;
}
기능 :
public TestResponse test(string test1, string test2)
{
TestResponse r = new TestResponse();
r.Results = new Dictionary<string, object>[1];
r.Results[0] = new Dictionary<string, object>();
r.Results[0].Add("field1", 26);
Dictionary<string, object>[] d = new Dictionary<string, object>[1];
d[0] = new Dictionary<string, object>();
d[0].Add("inner", 28);
r.Results[0].Add("dictionary", d);
return r;
}
실행이 오류 메시지를 제공하지만 난 살아야 올바른 knowntype 거 같아요
는 나는 다음과 같은 오류가 발생합니다 ?
CISICPD.CPDClient t = new CISICPD.CPDClient();
CISICPD.TestResponse response = t.test("dgdf", "dfsdfd");
나는 그 변경을하고 서비스 참조를 업데이트 한 것과 똑같은 메시지를 받고 있습니다. – user1677973
ok ive는 문제가 무엇인지 발견했습니다. - knowntype 속성이 무시되었습니다. 서비스 참조를 추가/업데이트하여 생성 된 reference.cs 파일은 testresponse 클래스에 대한 유형을 가지고 있지 않습니다. 코드에 추가하면 제대로 작동합니다. 그렇다면 reference.cs 파일을 생성 할 때 knowntype을 무시하는 이유는 무엇입니까? – user1677973
저는 일반적으로 서비스 참조를 사용하지 않으므로 KnownType 특성이 생성되지 않는 이유가 확실하지 않지만 DataContractSerializer를 사용할 때만 발생하는 것으로 보입니다. 명령 줄에서 svcutil을 수동으로 실행하고 XmlSerializer를 지정하면 "svcutil YourServiceURL/serializer : XmlSerializer/noConfig" –