0

I'm developing a WCF with two Classes as DataContracts. One of them is a Data Structure developed by myself which manages Objects as JSON one, it names JSON; the other is just a Customized Object that my WebService recieve, it names Emission. I have three methods; one is for create policies, other one retrieves a policy and the last one consults catalogs in a dynamical way using JSON class. My problem comes within an error message like this:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ... The InnerException message was 'Error in line 1 position 823. Element ... contains data of the 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfanyType' 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.'.
Please see InnerException for more details."

I was looking for an answer then I noticed that the cause of my problem was a property in my JSON class which is a list of generic Objects. I need this property in my client to initialize the object I expect to recieve, so this list could contain strings or another List of Objects that's why I need this kind of item.

I've tried to use sort of KnownTypes with no success but I don't know if I'm doing something wrong

[KnownType(typeof(Object[]))]
[KnownType(typeof(List<List<Object>>))]
[KnownType(typeof(List<object>))]
[KnownType(typeof(List<string>))]
[KnownType(typeof(List<List<string>>))] 

It is important to say that if I SET value property as internal everything goes fine even JSON class in client side although value property is never shown. Attach a shred of my code:

public class JSON
{
    #region
    [DataMember]
    public List<Object> value { get; set; }  This cause the problem
    //public List<Object> value { get; internal set; }  This allow everything happens fine
    [DataMember]
    public List<string> errors { get; set; }
    [DataMember]
    public Regex pattern { get; internal set; }
    [DataMember]
    internal Regex commaPattern { get; private set; }
    #endregion
}

[ServiceContract(Namespace = "http://EmissionService")]
public interface IEmissionService
{
    [OperationContract]
    [WebGet(UriTemplate = "Emissions/getCatalog", ResponseFormat = WebMessageFormat.Json)]
    string getCatalog(JSON request);

    [OperationContract]
    [WebInvoke(UriTemplate = "Emissions/createPolicy", ResponseFormat = WebMessageFormat.Json, Method = "POST")]
    string createPolicy(Emission emissionRequest);

    [OperationContract]
    [WebGet(UriTemplate = "Emissions/getPolicy", ResponseFormat = WebMessageFormat.Json)]
    JSON getPolicy(JSON request);
}

I hope you can really help me. Thanks in advice!


C++ function argument losing part of address

I got a really weird bug(?) on Win8x64 driver in C++, which crashes the system.

bool funcA(typedef1 arg1, typedef2 arg2)
{
    funcB(arg1, arg2);
    return true;
}


void funcB(typedef1 arg1, typedef2 arg2)
{
    ...do something
    funcD(....)
    ....
}

Background info: -- I did notice the driver crashes seemingly at random place of the codes, but didn't check why. - I'm making some changes in "funcD()", not related to the crash. - I compiled the binaries with debug, and noticed (now several time) that it crashes at the beginning of "funcB".

Problem: The issue is with the address of "arg2". The correct "arg2" address is there inside "funcA", which calls "funcB". But once inside "funcB", the address for "arg2" gets truncated.

e.g. arg2 = 0xffffe000'01ace148 while in "funcA", which then passes to calling "funcB". But inside "funcB", it becomes arg2 = 0x00000000'01ace148

I really have no idea how this can happen, so any suggestion welcomed! Don't think my changes in the downstream "funcD" could have caused this, yeah?

EDIT:

Both "typedefs" are pointer to some different structs.

Notice "funcA" doesn't do anything except calling "funcB" directly with the exact same arguments it receives. And both "funcA" and "funcB" have the same parameters (different return type tho), yet "funcA" has no problem receiving the arguments' addresses.

4

2 回答 2

0

编译器必须知道对象列表可以包含的所有类型,反序列化才能工作。

于 2013-11-22T14:21:03.027 回答
0

一个可能的环绕可能是在您的数据合同中使用数组而不是列表,ToArray()ToList()在您的服务中适当地使用。

于 2013-11-22T14:13:21.350 回答