datacontract

WCF DataContract

If I don't keep Service Contract, proxy and Service in separate assembly, Service contracts and Proxies resides in Client assembly, And service resides in Service assembly. If I do not keep data contract in a separate assembly, where should it reside, Client side or Service side? Can Data Contracts reside in both assemblies? ...

WCF Relocation of DataContracts

This is a fully functional WCF Hello World program. I.e. I am able to run this program without any Exception. using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace DataContractsNamespace { [DataContract] public class Account...

WCF: return only necessary properties on json

Because of performance tuning I would like to return only necessary properties. Is there a possibility/workaround? Pseudo / sample code to understand: [DataContract] public interface IMemberOverview { [DataMember] public int Id { get; set; } [DataMember] public string Name { get; set; } } [DataContract] public interfac...

WCF: DeSerialize string datamember as int

Hi everyone, I really can't figure this one out! (if it's even possible). From a WCF service we are receiving product information. A product datacontract has some members that are defined as strings (but are actually integers), but we want to process them as integers. When I change the datatype in the contract on the client side from...

WCF DataContract - marking member IsRequired=false

I have a contract as follows: [DataContract] public class MyObj { [DataMember(IsRequired=true)] public string StrA {get; private set;} [DataMember(IsRequired=false)] public string StrB {get; private set;} } What exactly does IsRequired mean? Does IsRequired=false mean that I can pass an instance of MyObj across the wi...

How to avoid processContents="lax" in WCF WSDL from classes implementing IXmlSerializable?

I have a wcf service written in a contract-first fashion. As some of the elements in the schema uses attributes, I had to create a custom serialization for this (using IXmlSerializable). Below is a snippet of the schema, and the classes, as well as the schema from the wsdl output. My problem is that even though I render the xsd for my I...

WCF Service that returns a custom class generates errors in Reference.cs

I have a WCF Service project in Visual Studio 2008 that contains about 12 methods, some of which return primitive types like bool or string. I also have a Visual Studio Unit Test Project that references the published WCF Service. The Test Project compiles successfully when all the return types are primitive. If I add a new method to the...

How do I add an XML attribute using DataContract

Hi I have a simple class I'm serializing. [DataContract(Name = "Test", Namespace = "")] public class Test { [DataMember(Order = 0, Name = "Text")] public string Text { get; set; } public Test() {} } This kicks out the following XML: <Test> <Text>Text here</Text> </Test> What I want is: <Test> <Text type="My...

WCF: Enforce equal DataContracts on both sides

Hi all, I'm wondering if it is possible to have WCF make sure that the DataContracts on both sides of a connection are exactly the same (and throw an exception when trying to connect if they are not). For example, imagine this service: [DataContract] enum State { [EnumMember] Red, [EnumMember] Yellow, [EnumMember] ...

WCF DataContract with an abstract DataMember array

I can't make this scenario work. Here's the pattern- [DataContract] /*abstract*/ class BaseT { ... } [DataContract] class ChildT : BaseT { ... } [DataContract] class MessageContents { [DataMember] public BaseT[] XX; // Array of BaseT objects. I need WCF to somehow figure out that they're actually ChildT. } // ...receive a web...

Why am I using the KnownType attribute wrong?

I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; s...

WCF Proxy generation

Hi, I'm generating proxy using svcutil tool. My contract methods return objects of particular type. However generated proxy client interface has return value of type object. What is more I get exception with message: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail] : The formatter threw an exception while tryi...

DataContract & DataMember attributes - how they affect type

Hi, what is the difference between class without DataContract attributes: public class BankOperationResult { public int CurrentAmount { get; set; } public bool Success { get; set; } } and the same class with DataContract attributes: [DataContract] public class BankOperationResult { [DataMember] public...

WCF, containers in DataContract

Hi I need to pass some container of objects to WCF call [DataContract] class Foo { // other fields omited [DataMember] public List<Foo> MyList; } Is it OK for serialization? If not what are my options? ...

WCF: Exposing readonly DataMember properties without set?

I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed to add a [DataMember] property without having both get and set. So - is there a way to ...

WCF multiple data contracts or multiple service contracts representing multiple data model classes?

In my WPF application data model I have multiple classes representing data for interaction with backend DB through WCF self hosted service. Should I have multiple Data Contracts or multiple Service Contacts or Endpoints in my WCF Sevice for representing these multiple WPF data model classes? What is correct (or maybe the only) way to a...

What is the advantage of using DataContractAttribute over SerializableAttribute?

I have found that my WCF services work normally when the data types involved doesn't have the [DataContract], but the [Serializable] instead. But all the WCF tutorials shows the first one instead of the latter. Why? ...

DataContractJsonSerializer Compatibility

I have a silverlight control which makes an HttpWebRequest to an HttpHandler on the server side. The request is a post. The body of the post is an object serialized using the DataContractJsonSerializer. The Silverlight control is SL 4.0 Beta and the Handler is .net 4.0 Beta. When i inspect the streams in the silverlight control the seria...

Extending .NET 2.0 class library for WCF use

We publish a class library that must remain compatible with .NET 2.0. However, we would also like to use this class library internally for WCF-based projects. Reading e.g. expose-object-from-class-library-using-wcf brings up an approach for using 2.0 class libraries by creating DataContractSurrogate objects to map 2.0 classes. Howev...

Creating a service-only subclass of a WCF DataContract class

Is the following concept possible, or will I have trouble serializing this to the Client. Assuming that all comms are only dealing with BaseContractClasses but the Server uses the special sub-class to collate extra server-only data. [DataContract] public class BaseContractClass { [DataMember] public int valueToTransmit; } public cl...