datacontract

Configuring WCF data contract for proper JSON response

非 Y 不嫁゛ 提交于 2019-12-02 09:21:12
问题 I manage a number of Bed & Breakfast websites and run a kind of booking engine to help the client do bookings directly on their website (as opposed to going to another site to close the deal). I am working on creating a web service using ASP.NET WCF to create a JSON response about room availability of the hotels I manage. I have configured the web service to serialize the response in JSON. Everything works reasonable well EXCEPT I cannot quite construct the proper objects to get the JSON

WCF: Returning a derived object for a contract with base object (DataContractResolver)

≡放荡痞女 提交于 2019-12-02 04:09:14
I have have a WCF derived/base contract issue. I have a server interface/contract that returns a BaseThing object: [OperationContract] BaseThing Get_base_thing(); The server that implements this has a DerivedThing (derived from BaseThing ) and wants to return this as a BaseThing . How to tell WCF that I only want to transport the BaseThing part of DerivedThing ? If in Get_base_thing I just return a reference to a DerivedThing then I get a SerializationException server side. I think I need to define a DataContractResolver and I looked at the MSDN article Using a Data Contract Resolver but this

How to expose part of Entity as DataContract?

Deadly 提交于 2019-12-02 00:13:46
Up to now, when working with WCF, I have always been exposing the whole either EF generated entities, or POCOs(by modifying the T4 template to include DataContract and DataMember on POCOs and properties) as DataContract. Now, I have come across a situation that I cannot expose the whole thing, and need to explicitly specify my DataContract to be a subset of the entities. It worth saying that one of my entities is something like below: And I want to just expose Id, Name, CategoryId, Price. Insert/Update of rest of the fields ( ActiveFrom , InactiveDate , Supported ) is something that will be

WCF DataMember List<> without enclosing element

試著忘記壹切 提交于 2019-12-01 20:40:06
The following DataContract: [DataContract(Namespace = "http://namespace", Name = "Blarg")] public class Blarg { [XmlAttribute("Attribute")] public string Attribute{ get; set; } [DataMember(Name = "Record", IsRequired = false, Order = 4)] public List<Record> Record{ get; set; } } Serializes into this: <Blarg Attribute="blah"> <Record> <Record/> <Record/> <Record/> </Record> </Blarg> But I want this: <Blarg> <Record/> <Record/> <Record/> <Blarg/> The DataContractSerializer seems to be inserting the header parent automagically and I don't want it. How do I go about removing the wrapping <Record>

Expose object from class library using WCF

爱⌒轻易说出口 提交于 2019-12-01 18:54:34
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? You can use a DataContractSurrogate . ...You can apply the DataContract attribute to the Person class, but this is not always possible. For example, the Person class can be defined in a separate assembly over which you have no control. Given this

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

how to mark an interface as DataContract in WCF

你。 提交于 2019-12-01 03:08:20
i have two data classes which hold only data members(no functions). One is CallTask the other is SmsTask . These two classes have some common properties like ID , Tel . I put these common properties in a seperate interface class and i use this interface class in my project whenever appropriate. Now i added a WCFService to my project to share data between clients and server. Consider the following class design: public interface IGsmTask : IComparable { string TaskID { get; set; } string SessionID { get; set; } string Tel { get; set; } } class CallTask : IGsmTask { #region IGsmTask Members

Can I add a WCF DataContract to a complex type?

為{幸葍}努か 提交于 2019-11-30 17:35:31
问题 I have a complex data type, including a number of functions, as well as the usual get and get methods. My life would be considerably easier if I could use WCF so my client can also use this data type. Do I Ignore all the operations, putting [DataMemeber] only where needed. Put the class in question in a shared library assembly for both client and server to access. Thanks, Roberto PS. I realise that the question is probably not as well worded as it could be. 回答1: All that's transferred across

WCF: Data contract being converted to message contract

♀尐吖头ヾ 提交于 2019-11-30 16:24:00
My WCF service exports a single operation, marked with the catch-all action and reply action so that it represents a common entry point to the service: [ServiceContract] public interface IService { [OperationContract (Action="*", ReplyAction="*")] Message MyMethod (Message msg); } Client proxies are still generated as data contracts. What I'm finding, however, is that despite the client sending a data contract, when msg is serialized, the body appears to be the equivalent message contract to the data contract, not the data contract itself. Even this is fine, except that extracting the data

Is there a way to export an XSD schema from a DataContract

一世执手 提交于 2019-11-30 15:05:53
问题 I'm using DataContractSerializer to serialize/deserialize my classes to/from XML. Everything works fine, but at some point I'd like to establish a standard schema for the format of these XML files independent of the actual code. That way if something breaks in the serialization process I can always go back and check what the standard schema should be. Or if I do need to modify the schema the modification is an explicit decision rather then just a later affect of modifying my code. In addition