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


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

Customizing class serialization for dissimilar clients

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :.NET Framework
 
In my class (with DataContract attribute) some properties,  [DataMember( Name = "Name",Order = 1)] are used by existing WCF clients. Now, I need to modify/supplement it to have only _some_ of these properties  to be serialized/deserialized on behalf a new non-WCF client, while not disrupting the existing WCF clients' functionality. What would be your choice: to use OnSerializing/ISerializable (how  to avoid serializing some properties?), to go SurrogateSelector way or to use something else for non-WCF client, like XmlSerializer, LINQ to XML, or something else.  One complication is that I would need for my non-WCF client to modify XML output into a a customer XML format (KLM),  while preserving serialization order and hierarchy. Which way would require less effort and/or provide more flexibility? I am using .NET 3.5 SP1 -Nick


View Complete Post


More Related Resource Links

Class To Contract: Enrich Your XML Serialization With Schema Providers In The .NET Framework

  

The Microsoft .NET Framework 1.x provided minimal options for mapping classes to schemas and serializing objects to XML documents, making this sort of mapping quite a challenge. The .NET Framework 2.0 changes all this with Schema providers and the IXmlSerializable interface.

Keith Pijanowski

MSDN Magazine June 2006


Xml Serialization: choose tag name for class instances in a generic ObservableCollection / List

  

Hi,

I've creating a class called Graphics, deriving from a generic ObservableCollection where T is a custom class called Graphic :

public class Graphics : ObservableCollection<Graphic>
{
public Graphics()
{
}
}

Another class has a Graphics field. When I serialize to XML this class, this works fine :

<MyOtherClassInstance>
 <Graphics>
  <Graphic id="1">
  <Graphic id="2">
  <Graphic id="3">
 </Graphics>
</MyOtherClassInstance>

But I would like to have the following:

<MyOtherClassInstance>
 <Gs>
  <Gr id="1">
  <Gr id="2">
  <Gr id="3">
 </Gs>
</MyOtherClassInstance>

How can I process, I can't find a solution.

Please help.

Thanks


Xml Serialization: change tag name of class instances in a generic ObservableCollection / List

  

Hi,

I've creating a class called Graphics, deriving from a generic ObservableCollection where T is a custom class called Graphic :

public class Graphics : ObservableCollection<Graphic>
{
public Graphics()
{
}
}

Another class has a Graphics field. When I serialize to XML this class, this works fine :

<MyOtherClassInstance>
 <Graphics>
  <Graphic id="1">
  <Graphic id="2">
  <Graphic id="3">
 </Graphics>
</MyOtherClassInstance>

But I would like to have the following:

<MyOtherClassInstance>
 <Gs>
  <Gr id="1">
  <Gr id="2">
  <Gr id="3">
 </Gs>
</MyOtherClassInstance>

How can I process, I can't find a solution.

Please help.

Thanks


XML Class Serialization with dynamic XmlElementName

  

Hi dudes, I have a question:

 

Today I have the following scenario:

 

 [XmlRoot("Etiquetas")]
 public class Etiquetas : List<Etiqueta>
 {

 } 

 public class Etiqueta
 {
 private string _id;
 private string _ptbr;
 private string _enus;

 [XmlAttribute]
 public string id
 {
 get { return _id; }
 set { _id = value; }
 }

 [XmlElement("pt-br")]
 public string pt_br
 {
 get { return _ptbr; }
 set { _ptbr = value; }
 

Customizing ToolboxControl class when we rehost WorkflowDesigner

  

Hi all,

I'm creating an application that rehost workflow designer. What I did is following the tutorial from Apress' Pro WF 4 books.

The principle of the tutorial is:
1. Use WorkflowDesigner class to read workflow xaml file, and bind  WorkflowDesigner.View andPropertyView property into ContentControl in the UI.

2. Use System.Activities.Presentation.Toolbox.ToolboxControl class to create VS-like Toolbox so that user can drag-and-drop whatever activities that added into this toolbox
3. ToolboxControl uses ToolboxCategory and ToolboxItemWrapper to construct its content.

 

Okay, my question is here related to ToolboxItemWrapper class. Based on the documentation, the constructor is using a Class Type, not an Instance. So when we drag and drop, it will instantiate the class into and instance.
Here is the documentation:
http://msdn.microsoft.com/en-us/library/system.activities.presentation.toolbox

Class Diagrams

  
Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

Creating a Simple Class in C#

  
The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

  
In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

abstract away the source of the connection string using a class with a static property.

  
ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Encapsulation
Let's abstract away the source of the connection string using a class with a static property.

MessageQueue Class

  
This sample demonstrates two way communications using message queuing between a device application and a desktop application. One application sends book order messages to a message queue and another application receives these book orders from the message queue and responds to the device queue that the orders have been processed.

How to change the default page base class?

  

I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.

Thanks,

Adam


Customizing the UI around the Filters

  

I have started working on a new project and thought it would be a great idea to dig into the latest version of the Dynamic Data framework that shipped with VS2010.  For the most part, I am impressed, it seems to be pretty easy to extend and create a rich and flexibile UI -- at least that is what I thought until I got to working on a better layout for the filters.

The situation is this:

I have a table with 25 columns and I need to display around 10 different filters (basically and interactive report) -- the filters are of various types.

The problem:

How in the world do I custom the UI layout of the filters.  It seems that with the latest QueryFilterRepeater control we have been left with almost nothing to work with (outside of turning filters on/off and setting the FilterUIHint).  What if I wanted to wrap all of the filters in an expand/collapse region and then inside of that have then sitting in a table of no more than 4 columns (so with 10 filters I wold have 3 rows). 

I have tried extending the QueryFilterRepeater but it seems like there is nothing in that class that we can work with (the data binding events are not even used).

Am I missing something, or am I just out of luck right now?


Can I replace the EntityObject as base-class in Entity Designer 3.5 sp1?

  

I'm using EF3.5sp1 for a project, and I've been working around many of its problems... as such, my entity partial classes have a lot of logic in them for change-tracking and whatnot.  Obviously, I'd like to factor this logic out into a common base class, but of course all my objects must derive from EntityObject.  Is it possible to tell them to derive from some class of my own invention (which would actually likely derive from EntityObject themselves)?

I'd rather avoid editing the EDMX file unless the changes will be safe on entity-model-update, since I'm still making changes to the database schema in this early state of my project.

Thanks

Also, is there any good workaround for the fact that the change isn't tracked when you change EntityReference.EntityKey?


Singleton Pattern and Abstract Class

  

I know what Singleton Pattern means and Abstract class means.

What I wanted to know was how would this apply to real world.

Could anyone give me any good example or simple explanation.

Say I have a simple website, why would I use any of the above if any.

Why would it simplify my architechture.

Thanks in advace. 


How to implement custom HttpContext for each request under class that implements IHTTPHandler

  

Hello All,

I created an application and implemented IHTTPHandler for all incoming request ending with ".aspx" extension.

Under "ProcessRequest" module, I am creating an instance of HttpContext (with URL attributes different from my application's URL i.e. if I am working on localhost then speciying Yahoo.com as its URL) and assigning it to "context" which comes as method argument.

After redirection, an error is generated. Also, the custom HTTPContext is not passed to the requested page (default.aspx, in my case.)

Code is as follows.

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
        Try
            Dim requestedUrl As String
            Dim targetUrl As String
            Dim urlLength As Integer
            'Save settings which will be used while redirecting to appropriate page
            requestedUrl = context.Request.RawUrl
            If requestedUrl.IndexOf("?") >= 0 Then
                targetUrl = requestedUrl.Substring(0, requestedUrl.IndexOf("?"))
            Else
                targetUrl = requestedUrl
            End If
            If targetUrl = Nothing Or targetUrl.Length = 0 Then
                targetUrl = requestedUrl
            End If
            urlLengt

Using a GenericHandler as a WebResource inside a Class Library

  

Hi,

I hope this is the right place to ask this question.

I'm trying to make a control class library. I want to have a GenericHandler as a WebResource so I could call it from the web project that will use that control.

I need this handler will get parameters from the query string and return JSON data acourding to what it get in the QS.

I know how to create JS and images WebResources, so I tried the same on a generic handler I added to the class library project but all it does is return the source of the handler file and not the result.

 

Is what I'm trying to do possible? If so, what should I do?

 

Thank :-)


Using loginName to find ADInfo from an outside class

  

Hi,

I wrote a class to pull adinfo and for the life of me I can't seem to figure

out why it says "Invalid Login Name" no matter what I type in. If I leave

it blank it seems to work properly but it doesn't seem to be actually searching

the AD. I'll drop the whole class here, it's being initiated by a button click

on an outside form.

 

Thanks in Advance for any help Offered,
Postholes

 

 

Imports System.DirectoryServices
Imports Microsoft.VisualBasic
Imports System.String
Imports System.Collections
Imports System.Security.Principal
Imports System.Security.Permissions

Namespace LoginButton
    Public Class LoginButton

        'Class Variables
        Dim UserID As String = Nothing
        Dim DomainDN As String = ConfigurationManager.AppSettings("myConnectionString")
        Dim ADEntry As DirectoryEntry = New DirectoryEntry(DomainDN)
        Dim objSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
        Dim oResults As DirectoryServices.SearchResultCollection
        Dim oResult As DirectoryServices.SearchResult
        Dim RetArray As New Hashtable
        Dim page As Page = DirectCast(HttpContext.Current.Handler, Page)
        Dim TextLogin = DirectCast(page.FindControl("
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