0
votes

I ame executing methods on a different computer via a WCF service here is a little example of my code:

the call to the method: return pipeProxy.SystemRequest(InstanceName, MethodName, Parameters);

These are the method and interface:

[ServiceContract]
    public interface IBlissRequest
    {
        [OperationContract]
        object SystemRequest(string InstanceName, string MethodName, object[] Parameters);
    }

    public class BlissRequest : IBlissRequest
    {
        public object SystemRequest(string InstanceName, string MethodName, object[] Parameters)
        {
            return System21.BlissProcessingUnit.BPU.RequestFromIBC(InstanceName, MethodName, Parameters); ;
        }
    }

as you can see i send 2 strings, and an array of objects, and i get an object back, this method is called by different locations and the objects can be diferent, if i send strings or integers through this method everything works fine, but when i try to send a List things go bad, and the method can not execute. now ive read that standard the DataContractSerializer is used and that i need to convert it to XmlSerializer to get it to work. ive found http://msdn.microsoft.com/en-us/library/ms733901.aspx but i can not get my example to work. could somone please point me in the good direction.

This is the exception that is thrown:

There was an error while trying to serialize parameter http://tempuri.org/:Parameters. The InnerException message was 'Type 'System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

The inner exception:

{"Type 'System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer."}

the object that need to be send are: if it is possible everything, if not just all the normal c# things like Lists

1
you'll need to serialize your list on the client, then deserialize it on the serverJonesopolis
@Jonesy but at runtime i dont know what is beeing send or received, so i dont knwo when it is a list or when it is a stringJeffnl
oh sorry i misunderstoodJonesopolis
"...things go bad" - Do you get an exception or an error message? What happens - nothing?Tim
@Tim I've updated my post with the exception detailsJeffnl

1 Answers

-1
votes

You do not need to add collection types to known types when used polymorphically in place of other collections or collection interfaces. For example, if you declare a data member of type IEnumerable and use it to send an instance of ArrayList, you do not need to add ArrayList to known types.

When you use collections polymorphically in place of non-collection types, they must be added to known types. For example, if you declare a data member of type Object and use it to send an instance of ArrayList, add ArrayList to known types.

This does not allow you to serialize any equivalent collection polymorphically. For example, when you add ArrayList to the list of known types, this does not let you assign the Array of Object class, even though it has an equivalent data contract. This is no different from regular known types behavior on serialization for non-collection types, but it is especially important to understand in the case of collections because it is very common for collections to be equivalent.

During serialization, only one type can be known in any given scope for a given data contract, and equivalent collections all have the same data contracts. This means that, in the previous example, you cannot add both ArrayList and Array of Object to known types at the same scope. Again, this is equivalent to known types behavior for non-collection types, but it is especially important to understand for collections. Known types may also be required for contents of collections. For example, if an ArrayList actually contains instances of Type1 and Type2, both of these types should be added to known types.

You can find an example here, under Collections and Known Types.