datacontract

Silverlight WCF service consuming inherited types in datacontract

Hi, Im trying to consume a WCF service in silverlight... What I have done is to create two seperate assemblies for my datacontracts... Assembly that contains all of my types marked with data contracts build against .Net 3.5 A Silverlight assembly which links to files in the 1st assembly. This means my .Net app can reference assembl...

WCF with multiple services and namespace issues

I have created a number of WCF Services, for arguments sake they are called Service1 and Service2. Both of the services return (at some point, possibly through a relationship inside an object) a Customer object. For testing sake, I have added a GetCustomer() method to both Service1 and Service2 and I have added a service reference to b...

WCF & optional XmlElements (no datacontract)

I asked a question about deserializing based on an attribute with data contracts. Apparently this isnt possible so I have to convert my DataContract to use XmlElement's (see http://stackoverflow.com/questions/2177079/net-represent-xml-in-class-without-xsd) I'm assuming datacontracts cannot intermingle with xmlelements. How can I define...

DataContract Serialization - Base class property names not working.

I have a base class like the following: [Serializable] public class SerializableDomainObject<T> { public SerializableDomainObject() { ID = Guid.NewGuid(); } [DataMember(Name="ID", Order = 0)] public Guid ID { get; private set; } public void Save() { // serialize } public void Load()...

Generate WCF DataContract from XSD

I want to be able to Generate WCF C# DataContract from XSD file, preferably using the xsd.exe tool. What is the easiest way for it to auto generate the [DataContract] and [DataMember] on each of my items? Or is there a better approach? I am trying to avoid having to recreate the Data Contract each time the XSD file is changed and regen...

XML Serialization - Is it possible to serialize a model in this way?

I have the following model: public class ABaseObject { private Guid id = Guid.NewGuid(); public ABaseObject() { } public Guid ID { get { return id; } } } public class ADerivedObject : ABaseObject { public ADerivedObject() { } public string Name { get; set; } } public class AObjectCollection<T> { ...

Creating WCF DataContracts dynamically from code

Given the fact that I have a fully dynamic object model, that is, I have no concrete classes defined anywhere in code, but I still want to be able to create WCF DataContracts for them so I can use them in operations. How can I achieve this? My concrete class "Entity" implements ICustomTypeDescriptor which is used to present the various ...

Two WCF services return the same datacontract to silverlight client

I have two WCF services which are logically different and I wish to keep them seperate. They each have an operation which returns the same datacontract. A single silverlight client consumes both services. When I add a service reference in the silverlight client to each service, the single datacontract ends up twice in the generated co...

Passing an instance of anonymous type over WCF

I have a WCF service method that expects an object and then retrieves its properties using reflection. On the client side I create an anonymous type object var obj = new {FirstName="John", LastName="Doe"} and pass it to the method. I'm getting an exception: Type '<>f__AnonymousType0`2[System.String,System.String]' cannot be serial...

Multiple WCF services referencing the same data contracts

I am building a set of WCF services that share common data contracts (or entities if you prefer). These are simple data transfer objects that are decorated with DataContract and DataMember attributes. I am explicitly specifying the name and namespace. In trying to follow the principles of IDesign's recommendation of averaging 12 members ...

Does datacontract serialization uses reflection?

XmlSerialization creates a serializer proxy for each class. The proxy resides in a different assembly so it can serialize only public fields. DataContract serialization can serialize private fields too. Does it mean it uses reflection? Isn't it slower than using a proxy (except for the first time)? ...

Perceived Inefficiencies in Data translation in web Services

I have been writing web services for about a year now and it seems that the process I use to get data from the Database all the way to display to the user and back again has some inefficiencies. The purpose of this question is to make sure that I am following best practices and not just adding extra work in. Here is the path for data ...

Clone Whole Object Graph....

While using for an object this code to serialize it: public object Clone() { var serializer = new DataContractSerializer(GetType()); using (var ms = new System.IO.MemoryStream()) { serializer.WriteObject(ms, this); ms.Position = 0; return serializer.ReadObject(ms); ...

web service data type (contract)

hi, i have a general design question. we have a fairly big data model that represents an clinical object, the object itself has 200+ child attributes in the hierarchy. and we have a SetObject operation, and a GetObject operation. my question is, best practice wise, would it make sense to use that single data model in both operations o...

Using custom DataContractResolver in WCF, to transport inheritance trees involving generics

I've got a WCF service, in which there are operations which accept a non-generic base class as parameter. [DataContract] class Foo { ... } This base class is in turn inherited, by such generics classes as [DataContract] class Bar<T> : Foo { ... } To get this to work, I'd previously have to register KnownTypes for the Foo class, and...

Why can't I use WCF DataContract and ISerializable on the same class?

Hi all, I have a class that I need to be able to serialize to a SQLServer session variable and be available over a WCF Service. I have declared it as follows namespace MyNM { [Serializable] [DataContract(Name = "Foo", Namespace = "http://www.mydomain.co.uk")] public class Foo : IEntity, ISafeCopy<Foo> { [DataMember(Order = 0)] ...

WCF - (Custom) binary serialisation.

I want to be able to query my database over the web, and I am wanting to use a WCF service to handle the requests and results. The problem is that due to the amount of data that can potentially be returned from these queries, I'm worried about how these results will be serialised over the network. For example, I can imagine the XML seria...

WCF DataContract with readonly properties

Hi, I'm trying to return a complex type from a service method in WCF. I'm using C# and .NET 4. This complex type is meant to be invariant (the same way .net strings are). Furthermore, the service only returns it and never recieves it as an argument. If I try to define only getters on properties I get a run time error. I guess this is b...

Client WCF DataContract has empty/null values from service

I have a simple WCF service that returns the time from the server. I've confirmed that data is being sent by checking with Fiddler. Here's the result object xml that my service sends. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; <s:Body> <GetTimeResponse xmlns="http://tempuri.org/"&gt; ...

DataContractJsonSerializer produces list of hashes instead of hash

I would expect a Dictionary object of the form: var dict = new Dictionary<string,string>() { {"blah", "bob"}, {"blahagain", "bob"} }; to serialize into JSON in the form of: { "blah": "bob", "blahagain": "bob" } NOT [ { "key": "blah", "value": "bob" }, { "key": "blahagain", "value": "bob"}] What is the reason for what app...