datacontract

DataContract for enums in WCF

ぃ、小莉子 提交于 2020-01-02 04:53:06
问题 I have a enum that I use via a WCF service in a .Net project. Now I want to add another enum, specified in the same way as the first. But the second one does not get registered in Reference.cs, and therefore is not recognized from the project consuming the WCF service. I have tried to re-write everything as I read that there is an automatic count that is confused if one copy-pastes the enum members. I checked that the service reference is not re-using types in referenced assemblies.

WCF datacontract vs class serialize

自闭症网瘾萝莉.ら 提交于 2020-01-02 02:31:07
问题 I understand that we can have more controls on a class if we use datacontract, however, consider the following 2 cases [DataContract] public class Customer { [DataMember] public string CustomerName {get; set;} [DataMember] public int Age{get; set;} } and public class Customer { public string CustomerName {get; set;} public int Age{get; set;} } They both get serialized correctly on .net client. And personally I do not use second example. Can anybody point me the differences in the 2 classes? I

C# DataContractJsonSerializer fails when value can be an array or a single item

人盡茶涼 提交于 2020-01-01 05:39:30
问题 I use the DataContractJsonSerializer to parse a json string into a object hierarchie. The json string looks like this: { "groups": [ { "attributes": [ { "sortOrder": "1", "value": "A" }, { "sortOrder": "2", "value": "B" } ] }, { "attributes": { "sortOrder": "1", "value": "C" } } ] } As you can see the sub value of "attributes" can be an array or a single item. I found the code part where the problem occures: [DataContract] public class ItemGroup { [DataMember(Name="attributes")] public List

Using WCF with abstract classes

余生长醉 提交于 2019-12-31 09:21:29
问题 How do I define DataContract for abstract classes in WCF? I have a class "Person" which I communicate successfully using WCF. Now I add a new class "Foo" referenced from Person. All still good. But when I make Foo abstract and define a sub class instead it fails. It fails on the server side with a CommunicationException, but that doesn't really tell me much. My simplified classes made for testing: [DataContract] public class Person { public Person() { SomeFoo = new Bar { Id = 7, BaseText =

Using WCF with abstract classes

元气小坏坏 提交于 2019-12-31 09:21:13
问题 How do I define DataContract for abstract classes in WCF? I have a class "Person" which I communicate successfully using WCF. Now I add a new class "Foo" referenced from Person. All still good. But when I make Foo abstract and define a sub class instead it fails. It fails on the server side with a CommunicationException, but that doesn't really tell me much. My simplified classes made for testing: [DataContract] public class Person { public Person() { SomeFoo = new Bar { Id = 7, BaseText =

C# data contract for complex JSON object

痞子三分冷 提交于 2019-12-31 03:03:39
问题 This is probably something really simple and I looked everywhere and tried everything I could come up with. So I apologize if this is a simple search and I was just looking for the wrong thing. I'm also new to data contracts and somewhat JSON so this probably isn't really that complex. I am creating an API to ingest JSON and store it in our database. The JSON will look something like this: { "appname" : "MyApp", "key" : "Test123", "data" :[ { "data1" : "10551296", "data2" : "TrainingIns",

Expose object from class library using WCF

人盡茶涼 提交于 2019-12-31 01:02:14
问题 I'm using a class library that exposes a few objects. These objects have a couple of properties that hold data my clients need. I'd like to create a WCF service that returns the objects to my clients but I cannot update the class library in order to add the DataContract and DataMember attributes. What is the easiest way of exposing these objects? 回答1: You can use a DataContractSurrogate. ...You can apply the DataContract attribute to the Person class, but this is not always possible. For

WCF DataContract with readonly properties

江枫思渺然 提交于 2019-12-30 02:45:06
问题 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 receives it as an argument. If I try to define only getters on properties I get a run time error. I guess this is because no setters causes serialization to fail. Still, I think this type should be invariant. Example: [DataContract] class A { [DataMember] int ReadOnlyProperty

Multiple WCF services referencing the same data contracts

自作多情 提交于 2019-12-30 02:43:14
问题 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 per service contract, I am breaking my service project into multiple services. My data contracts are in a separate assembly that I can provide to our clients

WCF DataContract ToString function

感情迁移 提交于 2019-12-29 08:57:07
问题 Can you override the ToString function in a WCF DataContrat? Right now I have: [DataContract] public class Keyword { public int ID { get; set; } public string Name { get; set; } public override string ToString() { return Name; } } But it doesn't seem to work. Anyway to get this working? 回答1: Remember too that if you own both the server and the client, that often you can use a shared library for data contracts rather than generating a client proxy. If you do that, then you can have the same