.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Is DataContract not nessecary?

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :WCF
 

Hi

I'm new to WCF. Are DataContract and DataMember not required? I tried to make a class which consisted of simple types, string DataTime and similar and uploaded it to a webserver. It seems that I was able to transfer a List of my new classes without using DataContract and DataMember. I thought I needed to use them – or?




View Complete Post


More Related Resource Links

Is it a good practice to use DataContract attributes on business entities

  
Hi Folks, Currently I am developing a framwork for travel industry and finally my framework will expose its operations in the form of WCF Service. I was wondering if it is a good idea to decorate your entities and class with DataContract attributes. I know this is required if you want your classes/fields to be serialized/deseralized.  However, by Adding these attributes mean you are making your entities service specific which I believe not a good idea. Service and domain specific entities should be seperate. One solution to this would be to make DTOs and decorate them with these attributes and this make sense as core purpose of these DTOs is serialization and deserialization. What can be other options....? Please share your thoughts. Thanks, Naeem

Problem: DataContract and DataMember attributes are not being recognized

  
I am having a strange problem. My service is otherwise working fine. However, now I want to add a custom object to be sent over to clients. I created a class to hold the data applied DataContract and DataMember attributes. However, compiler is not recognizing these attributes and giving me following error. The type or namespace name 'DataContractAttribute' could not be found (are you missing a using directive or an assembly reference?)  I could not figure our what assembly do I need to refer to. I am using VS2010 on WinXP. Thanks. kr

WCF Service "DataContract" conflict error

  
Hi,I am consuming two wcf services in my workflow. The services have the same datacontract with name "Consumer".My Workflow building successfully, But when i am trying to publish my workflow i am getting the "consumer" datacontract conflit error. The error is :DataContract for type 'Service1.Consumer' cannot be added to DataContractSet since type 'Service2.Consumer' with the same data contract name 'Consumer' in namespace 'http://MyWorkflow' is already present and the contracts are not equivalent.Suggest me how to solve this conflict.Thanks in advance.

How do i pass my datacontract into my business layer without a circular reference????

  
Ok, this architecture is fairly new to me, so I need a few good pointers.  I've searched the topic, but still don't have a clear understanding on what I'm missing.   I have a presentation layer, which displays my data and forms. I have a WCF service, a business layer and a dataAccess Layer I am trying to read data from on OLD!! foxpro .dbf file.  I've read all the articles on why not pass Datasets, etc so I'm trying to learn how to pass data contracts.  I have the following in my WCF [ServiceContract] public interface IService1 { [OperationContract] void SaveNDFData(string storedprocedure, ndfContractLibrary.NDFDataParam[] ndfData); <strong>[OperationContract] List<ndfContractLibrary.NDFDRawData> getRawNDFD();</strong> } I have a separate library for my dataContracts as i know later I will have several.  I'm using this as a generic List<> [Serializable] [DataContract] public class NDFDRawData { private int batchNumber; [DataMember] public int BatchNumber { get { return batchNumber; } set { batchNumber = value; } } private int sampleNumber; [DataMember] public int SampleNumber { get { return sampleNumber; } set { sampleNumber = value; } } private decimal invitroHour; [Da

Different DataContract in Response

  
Hi, I want to expose different data contaract because passing collection of data to service and process the data if any error occured then i add different contract for error message Thanks, Sen

DataContract & json i dont know how to do this...

  
Hello,at work we are migrating all the application to .Net 4.0 and leaving behind the Newtonsoft json serializer with the Microsoft serializer.the thing is that in Newtonsoft you have a couple of attributes that apply to my needs.JsonObject(MemberSerialization.OptIn) <--- this makes that only serialize the properties that have the following attribute.JsonProperty("id")Is there a way of accomplish the same with datacontract or something???i dont want to make a custom converter, i have plenty of classes and make custom converters to all of them, its impossible...well... thanks for any info...greetings!!!

Weird serialization DataContract issue

  

Hi,

 

I am having very weird issue where values submitted by WCF client are not serialized. I have tested the DataContracts by using DataContractSerializer to serialize and deserialize Object to/from xml file and there are no issues.

 

Due to the commercial nature of the project I am unable to post the actual code but following illustrates the structure:

 

[DataContract]
[KnownType(typeof(Friend))]
public class Person
{
  private string name;

  [DataMember]
  public string Name { get { return name; } set { name = value; }}

  private Place location;

  [DataMember]
  public Place Location { get { return location; } set { location = value; }}
}

[DataContract]
public class Friend : Person
{
  

How do I serialize a DataMember in a DataContract as an XML attribute

  

Hello guys,

I have the following class what I return on my WCF webservice;

 

[DataContract(Namespace = "http://schemas.pi.operational.petrobras.com.br")]
  public class SimpleMeasure
  {
    
    private DateTime? measureDate;
    private string value;

    [DataMember]
    public DateTime? MeasureDate
    {
      get { return measureDate; }
      set { measureDate = value; }
    }

    [DataMember]
    public string Value
    {
      get { return this.value; }
      set { this.value = value; }
    }
  }

 

Ho do I make it return a soapResponse like this ?

<SimpleMeasure <

Unable to bind a List of a [DataContract] class to a ListBox

  

Hello,

 

I have a class who is used by Silverlight though RIA Services and who contains the [DataContract] and on its properties [DataMember].

That class is also used by my WPF Application and i have a List<myClass> which i want to bind it on ListBox.

 

The problem is when i bind the list, when i select an item in my listbox, the first item is always selected and the right-click doesn't work properly.

In fact, the behavior of UI is weird and badly refreshed.

But, before, the class didn't have DataContract/DataMember attributes and it worked fine.

 

Do you know, a workaround to continue to use that class and avoid to create an other class specially for databind ?

 

 

Regards,

Guillaume.


using inheritance in datacontract

  

HI,

Can i use inhericance in datacontract, so that i can define common properties under multiple datacontrace classes under a base class

I have multiple service methods in which some of the properties in datacontract are same. I want to create a base class with all the common properties for datacontract then specialized classes deriving from the this base class and adding extra properties as per their requirement.

But when i generate a proxy the base class properties are not coming directly on the child class, in proxy I have to do specilizedClass.Base.property. Is there a way, to generate a proxy class, such that child class direcly contains all the properties of base class.

Regards


singhhome

DataContract as Model

  

 Hi,
I'm wondering to use DataContract in one of the scenario instead of making duplicates Model?

Is it the good idea or I have to write Model?

Thanks,

 


Best Practice for writing DataContract for a multi row data set.

  

My Stored Procedure returns the following fields: DisplayName, CompCode, CompName, CompValue, CompFlag. For any caseid there may be multiple rows returned.

I want my WCF Web Service to  expose all the above mentioned fields in wsdl.

How should I write my DataContract so that the xml has multiple rows.

Is it ok to to put List<string> in DataMembers as shown below or is there another best practice?

[DataMember]
        public List<string> DisplayName { get; set; }

 

Thanks You.

 


Referring multiple DataContract DLLs in one component

  

Hi,

I am creating few WCF services. The number may be high. And we have used a pattern in each service to handle different targets. Now the issue is like each service is having 3 classes. And these three classes are similar in all sevrices with minor changes. These classes use corresponding data contracts in thier classes and the remaing logic is same. Now i am trying to reduce no of classes in each service. So I've added a class librray to solution and these classes are available in that library. And I am referring these library in each service. Since all services use this library, I am referring all data contracts in this newly created library.

My question is what is the impact of referring a dll(s) in class library. Is it ok to refer all dlls in one library and refer that library in each service? Earlier implementation is referring corresponding data contract dll in each service. Now all the data contracts are removed from services and moved to one library. Am I doing correct in terms of performance and maintainability?


WCF Fault DataContract Not Reconized By Compiler

  

Can someone tell me which library I need to include into my code to make the complier recognize my Fault [DataContract]?

 

Below is my code....

 

 

using

 

System;

using

 

System.Collections.Generic;

using

 

System.Linq;

using

 

using inheritance in datacontract

  

HI,

Can i use inhericance in datacontract, so that i can define common properties under multiple datacontrace classes under a base class

I have multiple service methods in which some of the properties in datacontract are same. I want to create a base class with all the common properties for datacontract then specialized classes deriving from the this base class and adding extra properties as per their requirement.

But when i generate a proxy the base class properties are not coming directly on the child class, in proxy I have to do specilizedClass.Base.property. Is there a way, to generate a proxy class, such that child class direcly contains all the properties of base class.

Regards


singhhome

DataContract usage

  

I am trying to understand when to use data contracts. So i have a very simple example to see if i am correct and if not please could someone advise:

I have a movie collection, for simplicity i need to view all movies and related data (director and star) and add directory and star.

Finally i would need to add a movie and other data.

My client would be a Windows Form (VB .Net).

So initially i would have a operation contract which will expose:

Function ViewAllMovies as dataset
Function ViewMoviesByStar (byval Star as string) as dataset

the above code would link to an external dll to call Stored Procedures from a database.

Now i need to insert some data:

InsertMovieName
InsertDirector (byVal DirectorName as string)

Now if my database has a Directors table with

DirectorID
DirectorName

I could have a Data Contract similar to

DataContract
Public class Director

Private DirID as Integer
Private DirName as string

[DataMember]
Public Property DirectorID as Integer
Get
...
Set
...
End property

[DataMember]
Public Property DirectorName as String
Get
...
Set
...
End property

and then i can map these datamembers to my client to pass these details to the stored procedure to insert into a database.

Problem creating DataContract with SVCUTIL

  

I am trying to create a DataContract for a simple REST based webservice using a XSD file.

However when I run:

 svcutil /dconly .\workcodes.xsd /out:workcodes.cs

I get the following error message:

Error: Cannot read .\workcodes.xsd.

    Cannot load file C:\home\timesheet_webpart\workcodes.xsd as an Assembly. Check the FusionLogs for more Information.

    Could not load file or assembly 'file:///C:\home\timesheet_webpart\workcodes.xsd' or one of its dependencies. The module was expected to contain an assembly manifest.

I do not know why it would be trying to load the XSD as an assembly. I researched the issue and was unable to find a solution.

Can anyone shed some light on this issue? I have att

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend