datacontractserializer

Getting bad generated code from “Update Service Reference”

徘徊边缘 提交于 2019-12-02 03:31:57
In VB.NET (using Visual Studio 2008) my WCF service has an interface something like: <ServiceContract()> _ Public Interface IThingService <OperationContract()> _ Function GetThingByNumber(ByVal thingNumber As MyKeyClass) As Thing <OperationContract()> _ Function GetThing(ByVal thingId As Guid) As Thing ' ... End Interface I recently changed two projects with similar code to use a basicHttpBinding rather than a wsHttpBinding. Everything compiles well on the service side. Now, in the a client app I choose "Update Service Reference". In one project, my resulting reference.vb seems correct--under

ExtensionDataObject not marked as serializable

你说的曾经没有我的故事 提交于 2019-12-02 01:20:02
Oi! I'm having issues serializing my session state. We have 2 components, our WCF and Web. Based on our AdministrationPartial.cs and Administration.svc we generate "Administration.cs" code for our web project with the following .bat file : svcutil.exe http://wcf_url.local/Administration.svc?wsdl /r:"{Path}\{Namespace}.dll" /d:"{Path}\{Namespace}\Code" I removed the personal data from the above statement and replaced it with {path} and {namespace}. The Administration.cs will be inside the Code map. In the Partial we have : [Serializable] public partial class MyObject { <Some code> } It

Setting the initial value of a property when using DataContractSerializer

不问归期 提交于 2019-12-01 15:36:27
If I am serializing and later deserializing a class using DataContractSerializer how can I control the initial values of properties that were not serialized? Consider the Person class below. Its data contract is set to serialize the FirstName and LastName properties but not the IsNew property. I want IsNew to initialize to TRUE whether a new Person is being instantiate as a new instance or being deserialized from a file. This is easy to do through the constructor, but as I understand it DataContractSerializer does not call the constructor as they could require parameters. [DataContract(Name=

Setting the initial value of a property when using DataContractSerializer

假装没事ソ 提交于 2019-12-01 15:18:07
问题 If I am serializing and later deserializing a class using DataContractSerializer how can I control the initial values of properties that were not serialized? Consider the Person class below. Its data contract is set to serialize the FirstName and LastName properties but not the IsNew property. I want IsNew to initialize to TRUE whether a new Person is being instantiate as a new instance or being deserialized from a file. This is easy to do through the constructor, but as I understand it

wcf deserialize enum as string

此生再无相见时 提交于 2019-12-01 14:58:42
I'm trying to consume a RESTful web service using WCF. I have no control over the format of the web service, so I have to make a few workarounds here and there. One major problem I cannot seem to get around, however, is how to make WCF deserialize an enum as a string. This is my code (names changed, obviously): [DataContract] public enum Foo { [EnumMember( Value = "bar" )] Bar, [EnumMember( Value = "baz" )] Baz } [DataContract] public class UNameIt { [DataMember( Name = "id" )] public long Id { get; private set; } [DataMember( Name = "name" )] public string Name { get; private set; }

wcf deserialize enum as string

狂风中的少年 提交于 2019-12-01 13:47:17
问题 I'm trying to consume a RESTful web service using WCF. I have no control over the format of the web service, so I have to make a few workarounds here and there. One major problem I cannot seem to get around, however, is how to make WCF deserialize an enum as a string. This is my code (names changed, obviously): [DataContract] public enum Foo { [EnumMember( Value = "bar" )] Bar, [EnumMember( Value = "baz" )] Baz } [DataContract] public class UNameIt { [DataMember( Name = "id" )] public long Id

WCF data serialization : can it go faster?

柔情痞子 提交于 2019-12-01 12:23:27
This question is sort of a sequel to that question. When we want to build a WCF service which works with some kind of data, it's natural that we want it to be fast and efficient. In order to achieve that, we have to make sure all segments of data road trip work as fast as they could, from data storage back-end such as SQL Server, to a WCF client who requested that data. While seeking for an answer on that previous question, we have learned, thanks to Slauma and others who contributed through comments, that the time consuming part of Entity Framework's (first) large query is object

Using a DataContractSurrogate with WCF REST

五迷三道 提交于 2019-12-01 11:49:23
问题 How can I use a DataContractSurrogate for my WCF REST service (hosted using a WebServiceHostFactory)? I don't see a way of adding one and even if I add a custom IOperationBehavior, the WebServiceHost automatically overwrites and ignores it. 回答1: You can achieve this with the following two steps: First, implement IDatacontractSurrogate interface: class MySurrogate : IDataContractSurrogate { public Type GetDataContractType(Type type) { //Implementation here } public object GetObjectToSerialize

DataContractJsonSerializer to skip nodes with null values

久未见 提交于 2019-12-01 02:16:41
I am using DataContractJsonSerializer to serialize my custom object to JSON. But i want to skip the data members whose values are null . If DataMember is null that node should not come in JSON string. How can I achieve this? Give me a simple code snippet to work with. You can use the EmitDefaultValue = false property in the [DataMember] attribute. For members marked with that attribute, their values will not be output. [DataContract] public class MyType { [DataMember(EmitDefaultValue = false)] public string Prop1 { get; set; } [DataMember(EmitDefaultValue = false)] public string Prop2 { get;

Why does WCF wrap request/response types in another XML element, and how to prevent this?

依然范特西╮ 提交于 2019-11-30 21:44:58
I have a simple echo service where I've defined one operation method and a pair of types for request/response: [ServiceContract(Name = "EchoService", Namespace = "http://example.com/services", SessionMode = SessionMode.NotAllowed)] public interface IEchoService { [OperationContract(IsOneWay = false, Action = "http://example.com/services/EchoService/Echo", ReplyAction = "http://example.com/services/EchoService/EchoResponse")] EchoResponse Echo(EchoRequest value); } The data types: [Serializable] [DataContract(Namespace = "http://example.com/services/EchoService", Name = "EchoRequest")] public