WCF ignore data contract not working - c#

I have a WCF Service hosted on IIS. Here is my Interface:
[ServiceContract]
[SilverlightFaultBehavior]
public interface IETC
{
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role = "XYZ")]
string GetStampXML();
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role = "XYZ")]
List<Stamp> GetStamps();
}
I am getting an error when I go to my WCF service through the web browser. The error is as follows:
Type 'System.Windows.Media.ImageSource' cannot be serialized. Consider marking it with the DataContractAttribute attribute.....
My stamps Class is:
[DataContract]
public class Stamp
{
private string _Name;
private string _SmallIcon = "";
private string _MediumIcon = "";
private string _LargeIcon = "";
private BitmapImage _SmallImage;
private BitmapImage _MediumImage;
private BitmapImage _LargeImage;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
[DataMember]
public string SmallIcon
{
get { return _SmallIcon; }
set { _SmallIcon = value; }
}
[DataMember]
public string MediumIcon
{
get { return _MediumIcon; }
set { _MediumIcon = value; }
}
[DataMember]
public string LargeIcon
{
get { return _LargeIcon; }
set { _LargeIcon = value; }
}
[IgnoreDataMember]
public BitmapImage SmallImage
{
get { return _SmallImage; }
set { _SmallImage = value; }
}
[IgnoreDataMember]
public BitmapImage MediumImage
{
get { return _MediumImage; }
set { _MediumImage = value; }
}
[IgnoreDataMember]
public BitmapImage LargeImage
{
get { return _LargeImage; }
set { _LargeImage = value; }
}
}
It is like the IgnoreDataMember is not being recognized. I tried it without the IgnoreDataMember figure it was going to only serialize the DataMembers, and that didn't work either. Any ideas why it seems to trying to serialize the BitmapImage?

What version of .net are you running? .NET 4 Data Contract does not require you to explicitly set Ignore attributes. You can test what's being produced by using DataContractSerializer and writing the content to the file. Create console application and reference your service project.
namespace SO_10281928
{
class Program
{
static void Main(string[] args)
{
var instance = new Stamp
{
Name = "Test",
SmallIcon = "Small Icon",
LargeIcon = "LargeIcon",
MediumIcon = "MediumIcon"
};
using (var stream = new FileStream(#"c:\temp\stamp.xml", FileMode.Create))
{
var ds = new DataContractSerializer(typeof (Stamp));
ds.WriteObject(stream, instance);
}
Console.WriteLine("Done.");
Console.ReadLine();
}
}
[DataContract]
public class Stamp
{
private string _Name;
private string _SmallIcon = "";
private string _MediumIcon = "";
private string _LargeIcon = "";
private BitmapImage _SmallImage;
private BitmapImage _MediumImage;
private BitmapImage _LargeImage;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
[DataMember]
public string SmallIcon
{
get { return _SmallIcon; }
set { _SmallIcon = value; }
}
[DataMember]
public string MediumIcon
{
get { return _MediumIcon; }
set { _MediumIcon = value; }
}
[DataMember]
public string LargeIcon
{
get { return _LargeIcon; }
set { _LargeIcon = value; }
}
public BitmapImage SmallImage
{
get { return _SmallImage; }
set { _SmallImage = value; }
}
public BitmapImage MediumImage
{
get { return _MediumImage; }
set { _MediumImage = value; }
}
public BitmapImage LargeImage
{
get { return _LargeImage; }
set { _LargeImage = value; }
}
}
public class BitmapImage
{
}
}
And the result is :
<Stamp xmlns="http://schemas.datacontract.org/2004/07/SO_10281928" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<LargeIcon>LargeIcon</LargeIcon>
<MediumIcon>MediumIcon</MediumIcon>
<Name>Test</Name>
<SmallIcon>Small Icon</SmallIcon>
</Stamp>

Related

Fill data to class

I have a c# class, I am creating object to put data in class , some data i have no able to do, here is my code
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
oNoteType.Value = new
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
Next you can see the class
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
The class "Invoice" has 4 fields to set data
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
As you can see in the code, I set data to "uBLVersionID" and "InvoiceTypeCode", but I have not been able to assign data to notefield, and I don't know to set "uBLExtensionfield".
Does someone know how to do that?
Code below compiles with no errors. I added missing classes. The line with the ******* is causing issues.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
//oNoteType.Value = new ******************************************** bad
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
}
}
public class CodeType
{
public string Value { get; set; }
}
public class IdentifierType
{
public string Value { get;set;}
}
public class UBLVersionIDType
{
public string Value { get; set; }
}
public class InvoiceTypeCodeType
{
public string Value { get; set; }
}
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public class IDType
{
}
public class NameType1
{
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
}
I solved myself, This is the REAL answer and its working fine
NoteType[] arrayNote = new NoteType[3];
NoteType oObj1 = new NoteType();
TextType oTextType = new TextType();
oTextType.Value = "This is Note 1";
oObj1.Value = oTextType.Value;
arrayNote[0] = oObj1;
oObj1.Value = "This is Note 2";
arrayNote[1] = oObj1;

Json data deserialzation returning null value for a property

private static int DefaultApiClientTimeout = 30;
public WorkItemDetail GetWorkItemDetail(
int userNumber, int userNumberExternal, string applicationId,
short computerNumber, DateTime wiDate, int wiSequence,
int wiDetailSequence, bool includeImage)
{
string uri = string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage);
WorkItemDetail result = ProcessRequest<object, WorkItemDetail>(uri, "GET", null);
return result;
}
public ResponseType ProcessRequest<RequestType, ResponseType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var result = ProcessRequest<RequestType>(uri, method, reqtype);
return JsonConvert.DeserializeObject<ResponseType>(result);
}
public string ProcessRequest<RequestType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var request = CreateWebRequest(uri, method);
var x = (HttpWebResponse)request.GetResponse(); //the exception :(
var strResult = new StreamReader(x.GetResponseStream()).ReadToEnd();
return strResult;
}
public WebRequest CreateWebRequest(string uri, string method = "GET")
{
string url = "http://localhost:3144/" + uri;
var request = WebRequest.Create(url);
request.ContentType = "application/json; charset=utf-8";
request.Method = method;
//Convert minutes to milliseconds.
request.Timeout = DefaultApiClientTimeout * 60000;
return request;
}
above is my entire code.
I have a problem in deserialzing jsondata. from my web api method data is returning correctly but when coming to client result i.e., above code while deserializing jsondata ImageInBytes property is getting null.
[Serializable]
public class WorkItemDetail : IWorkItemKey
{
private byte[] thumbnailImage;
private byte[] image;
private short wiDetailSequence;
private string workItemDetailType;
private int networkShare;
private string networkSharePath;
private string filePath;
private string displayImageFileName;
private string imagePath;
private DateTime workItemDate;
private string documentOcr;
#region Work Item Members
/// <summary>
/// This will actually be a ShortDate from the database
/// </summary>
public DateTime WorkItemDate
{
get { return workItemDate; }
set { workItemDate = value; }
}
private int wiSequence;
public int WISequence
{
get { return wiSequence; }
set { wiSequence = value; }
}
public short WIDetailSequence
{
get { return wiDetailSequence; }
set { wiDetailSequence = value; }
}
private short _otherSideWIDetailSequence;
public short OtherSideWIDetailSequence
{
get { return _otherSideWIDetailSequence; }
set { _otherSideWIDetailSequence = value; }
}
private string sourceType;
public string SourceType
{
get { return sourceType; }
set { sourceType = value; }
}
private string sourceIdentifier;
public string SourceIdentifier
{
get { return sourceIdentifier; }
set { sourceIdentifier = value; }
}
#endregion
private int _reason;
public int Reason
{
get { return _reason; }
set { _reason = value; }
}
private short _computerNumber;
public short ComputerNumber
{
get { return _computerNumber; }
set { _computerNumber = value; }
}
private string _computerName;
public string ComputerName
{
get { return _computerName; }
set { _computerName = value; }
}
private DateTime? _WIDateDest;
public DateTime? WIDateDest
{
get { return _WIDateDest; }
set { _WIDateDest = value; }
}
private int? _WISequenceDest;
public int? WISequenceDest
{
get { return _WISequenceDest; }
set { _WISequenceDest = value; }
}
private short? _WIDetailSequenceDest;
public short? WIDetailSequenceDest
{
get { return _WIDetailSequenceDest; }
set { _WIDetailSequenceDest = value; }
}
private short? _OtherSideWIDetailSequenceDest;
public short? OtherSideWIDetailSequenceDest
{
get { return _OtherSideWIDetailSequenceDest; }
set { _OtherSideWIDetailSequenceDest = value; }
}
public string WorkItemDetailType
{
get { return workItemDetailType; }
set { workItemDetailType = value; }
}
public int NetworkShare
{
get { return networkShare; }
set { networkShare = value; }
}
public string NetworkSharePath
{
get { return networkSharePath; }
set { networkSharePath = value; }
}
public string FilePath
{
get { return filePath; }
set { filePath = value; }
}
public string DisplayImageFileName
{
get { return displayImageFileName; }
set { displayImageFileName = value; }
}
public string ImagePath
{
get { return imagePath; }
set { imagePath = value; }
}
public byte[] ImageInBytes
{
get { return image; }
set { image = value; }
}
public byte[] ThumbnailImage
{
get { return thumbnailImage; }
set { thumbnailImage = value; }
}
private string ocrData;
public string OCRData
{
get { return ocrData; }
set { ocrData = value; }
}
private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
private bool? _isCorrespondence;
public bool? IsCorrespondence
{
get { return _isCorrespondence; }
set { _isCorrespondence = value; }
}
private bool? isCorrespondenceDBValue;
public bool? IsCorrespondenceDBValue
{
get { return isCorrespondenceDBValue; }
set { isCorrespondenceDBValue = value; }
}
private Guid? wfInstanceId;
public Guid? WFInstanceId
{
get { return wfInstanceId; }
set { wfInstanceId = value; }
}
private DateTime _transactionTime;
public DateTime TransactionTime
{
get { return _transactionTime; }
set { _transactionTime = value; }
}
private DateTime _endTime;
public DateTime EndTime
{
get { return _endTime; }
set { _endTime = value; }
}
private string _transactionType;
public string TransactionType
{
get { return _transactionType; }
set { _transactionType = value; }
}
private string _applicationId;
public string ApplicationId
{
get { return _applicationId; }
set { _applicationId = value; }
}
private string _applicationName;
public string ApplicationName
{
get { return _applicationName; }
set { _applicationName = value; }
}
private bool isFront;
public bool IsFront
{
get { return isFront; }
set { isFront = value; }
}
private int _userNumber;
public int UserNumber
{
get { return _userNumber; }
set { _userNumber = value; }
}
private string barcode1;
public string BarCode1
{
get { return barcode1; }
set { barcode1 = value; }
}
private string barcode2;
public string BarCode2
{
get { return barcode2; }
set { barcode2 = value; }
}
private string barcode3;
public string BarCode3
{
get { return barcode3; }
set { barcode3 = value; }
}
private string barcode4;
public string BarCode4
{
get { return barcode4; }
set { barcode4 = value; }
}
private string barcode5;
public string BarCode5
{
get { return barcode5; }
set { barcode5 = value; }
}
private bool? markSense1;
public bool? MarkSense1
{
get { return markSense1; }
set { markSense1 = value; }
}
private bool? markSense2;
public bool? MarkSense2
{
get { return markSense2; }
set { markSense2 = value; }
}
private bool? markSense3;
public bool? MarkSense3
{
get { return markSense3; }
set { markSense3 = value; }
}
private bool? markSense4;
public bool? MarkSense4
{
get { return markSense4; }
set { markSense4 = value; }
}
private bool? markSense5;
public bool? MarkSense5
{
get { return markSense5; }
set { markSense5 = value; }
}
private bool? markSense6;
public bool? MarkSense6
{
get { return markSense6; }
set { markSense6 = value; }
}
private bool? markSense7;
public bool? MarkSense7
{
get { return markSense7; }
set { markSense7 = value; }
}
private bool? markSense8;
public bool? MarkSense8
{
get { return markSense8; }
set { markSense8 = value; }
}
private bool? markSense9;
public bool? MarkSense9
{
get { return markSense9; }
set { markSense9 = value; }
}
private bool? markSense10;
public bool? MarkSense10
{
get { return markSense10; }
set { markSense10 = value; }
}
private string data;
public string Data
{
get { return data; }
set { data = value; }
}
private string auditTrail;
public string AuditTrail
{
get { return auditTrail; }
set { auditTrail = value; }
}
private short? displayImageHorizontalPixels;
public short? DisplayImageHorizontalPixels
{
get { return displayImageHorizontalPixels; }
set { displayImageHorizontalPixels = value; }
}
private short? displayImageVerticalPixels;
public short? DisplayImageVerticalPixels
{
get { return displayImageVerticalPixels; }
set { displayImageVerticalPixels = value; }
}
private short? displayImageHorizontalResolution;
public short? DisplayImageHorizontalResolution
{
get { return displayImageHorizontalResolution; }
set { displayImageHorizontalResolution = value; }
}
private short? displayImageVerticalResolution;
public short? DisplayImageVerticalResolution
{
get { return displayImageVerticalResolution; }
set { displayImageVerticalResolution = value; }
}
private byte? displayImageColorDepth;
public byte? DisplayImageColorDepth
{
get { return displayImageColorDepth; }
set { displayImageColorDepth = value; }
}
private int displayImageBytes;
public int DisplayImageBytes
{
get { return displayImageBytes; }
set { displayImageBytes = value; }
}
private byte[] displayImageMD5Hash;
public byte[] DisplayImageMD5Hash
{
get { return displayImageMD5Hash; }
set { displayImageMD5Hash = value; }
}
private string iclImageFileName;
public string ICLImageFileName
{
get { return iclImageFileName; }
set { iclImageFileName = value; }
}
private short? iCLImageHorizontalPixels;
public short? ICLImageHorizontalPixels
{
get { return iCLImageHorizontalPixels; }
set { iCLImageHorizontalPixels = value; }
}
private short? iCLImageVerticalPixels;
public short? ICLImageVerticalPixels
{
get { return iCLImageVerticalPixels; }
set { iCLImageVerticalPixels = value; }
}
private short? iCLImageHorizontalResolution;
public short? ICLImageHorizontalResolution
{
get { return iCLImageHorizontalResolution; }
set { iCLImageHorizontalResolution = value; }
}
private short? iCLImageVerticalResolution;
public short? ICLImageVerticalResolution
{
get { return iCLImageVerticalResolution; }
set { iCLImageVerticalResolution = value; }
}
private byte? iCLImageColorDepth;
public byte? ICLImageColorDepth
{
get { return iCLImageColorDepth; }
set { iCLImageColorDepth = value; }
}
private int iCLImageBytes;
public int ICLImageBytes
{
get { return iCLImageBytes; }
set { iCLImageBytes = value; }
}
private byte[] iCLImageMD5Hash;
public byte[] ICLImageMD5Hash
{
get { return iCLImageMD5Hash; }
set { iCLImageMD5Hash = value; }
}
private string preparedFilePath;
public string PreparedFilePath
{
get { return preparedFilePath; }
set { preparedFilePath = value; }
}
private string displayImageFullPath;
public string DisplayImageFullPath
{
get { return displayImageFullPath; }
set { displayImageFullPath = value; }
}
/// <summary>
/// The results of full page OCR for this image, if available. This field may
/// not always be populated depending on the service method invoked and/or configuration
/// of document OCR for the particular site.
/// </summary>
public string DocumentOcr
{
get { return documentOcr; }
set { documentOcr = value; }
}
private OcrDataRecord _ocrrecord;
/// <summary>
/// Fully parsed ocr data.
/// </summary>
public OcrDataRecord OcrRecord
{
get { return _ocrrecord; }
set { _ocrrecord = value; }
}
private string _workItemLogNote;
public string WorkItemLogNote
{
get { return _workItemLogNote; }
set { _workItemLogNote = value; }
}
private bool _isDeleted;
public bool IsDeleted
{
get { return _isDeleted; }
set { _isDeleted = value; }
}
public override string ToString()
{
return string.Format("WIDate: {0} ,WISequence: {1}, WIDetailSequence: {2}, WIDetailType: {3}",
WorkItemDate.ToShortDateString(), WISequence, WIDetailSequence, WorkItemDetailType);
}
private DateTime? _batchStartDate;
public DateTime? BatchStartDate
{
get { return _batchStartDate; }
set { _batchStartDate = value; }
}
private short? _batchSeqNum;
public short? BatchSeqNum
{
get { return _batchSeqNum; }
set { _batchSeqNum = value; }
}
private short? _envelopeSequence;
public short? EnvelopeSequence
{
get { return _envelopeSequence; }
set { _envelopeSequence = value; }
}
}
other code to return
public async Task<WorkItemDetail> GetWorkItemDetailAsync(int userNumber, int userNumberExternal, string applicationId, short computerNumber, DateTime wiDate, int wiSequence, int wiDetailSequence, bool includeImage)
{
using (HttpClient client = base.CreateHttpClient())
{
WorkItemDetail workitemdetail = new WorkItemDetail();
var service_result = await client.GetAsync(string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage));
await ValidateResponseAsync(service_result);
workitemdetail = await service_result.Content.ReadAsAsync<WorkItemDetail>();
return workitemdetail;
}
}

WCF generate proxy classes with namespace as it is in server side

I have below class:
namespace ESF.Engine.SharedObjects.CatalogManagement
{
[DataContract()]
public class Customer
{
private string _LastName;
private System.DateTime _BirthDate;
private decimal _MoneyInCash;
private bool _IsActive;
private string _AdditionalInfo;
private decimal _ITEMID;
private string _NAME;
[DataMember()]
public string LastName
{
get
{
return this._LastName;
}
set
{
this._LastName = value;
}
}
[DataMember()]
public System.DateTime BirthDate
{
get
{
return this._BirthDate;
}
set
{
this._BirthDate = value;
}
}
[DataMember()]
public decimal MoneyInCash
{
get
{
return this._MoneyInCash;
}
set
{
this._MoneyInCash = value;
}
}
[DataMember()]
public bool IsActive
{
get
{
return this._IsActive;
}
set
{
this._IsActive = value;
}
}
[DataMember()]
public string AdditionalInfo
{
get
{
return this._AdditionalInfo;
}
set
{
this._AdditionalInfo = value;
}
}
[DataMember()]
public decimal ITEMID
{
get
{
return this._ITEMID;
}
set
{
this._ITEMID = value;
}
}
[DataMember()]
public string NAME
{
get
{
return this._NAME;
}
set
{
this._NAME = value;
}
}
}
}
After adding Service Reference, the proxy for this class generated under namespace which is default for client application.
Is it possible to force the class proxy to be generated as it is in server?
Thanks for your time.

string[] and string to DataGridView-Datasource

i have collection of class "Microsoft.Exchange.Management.TransportLogSearchTasks.MessageTrackingEvent"
this is microsoft class.
this class build like the following class
public class MTE
{
private DateTime timestamp;
private string clientIp;
private string clientHostname;
private string serverIp;
private string serverHostname;
private string sourceContext;
private string connectorId;
private string source;
private string eventId;
private string internalMessageId;
private string messageId;
private string[] recipients;
private string[] recipientStatus;
private int? totalBytes;
private int recipientCount;
private string relatedRecipientAddress;
private string[] reference;
private string messageSubject;
private string sender;
private string returnPath;
private string messageInfo;
private new DateTime Timestamp
{
get { return timestamp; }
set { timestamp = value; }
}
public new string ClientIp
{
get { return clientIp; }
set { clientIp = value; }
}
public new string ClientHostname
{
get { return clientHostname; }
set { clientHostname = value; }
}
public new string ServerIp
{
get { return serverIp; }
set { serverIp = value; }
}
public new string ServerHostname
{
get { return serverHostname; }
set { serverHostname = value; }
}
public new string SourceContext
{
get { return sourceContext; }
set { sourceContext = value; }
}
public new string ConnectorId
{
get { return connectorId; }
set { connectorId = value; }
}
public new string Source
{
get { return source; }
set { source = value; }
}
public new string EventId
{
get { return eventId; }
set { eventId = value; }
}
public new string InternalMessageId
{
get { return internalMessageId; }
set { internalMessageId = value; }
}
public new string MessageId
{
get { return messageId; }
set { messageId = value; }
}
public new string[] Recipients
{
get { return recipients; }
set { recipients = value; }
}
public new string RecipientStatus
{
get { return[] recipientStatus; }
set { recipientStatus = value; }
}
public new int? TotalBytes
{
get { return totalBytes; }
set { totalBytes = value; }
}
public new int RecipientCount
{
get { return recipientCount; }
set { recipientCount = value; }
}
public new string RelatedRecipientAddress
{
get { return relatedRecipientAddress; }
set { relatedRecipientAddress = value; }
}
public new string Reference
{
get { return[] reference; }
set { reference = value; }
}
public new string MessageSubject
{
get { return messageSubject; }
set { messageSubject = value; }
}
public new string Sender
{
get { return sender; }
set { sender = value; }
}
public new string ReturnPath
{
get { return returnPath; }
set { returnPath = value; }
}
public new string MessageInfo
{
get { return messageInfo; }
set { messageInfo = value; }
}
}
When i am doing
Collection<MTE> newMTE = new Collection<MTE>();
datagridview1.datasource= newMTE;
datagrid1.datasource = newMTE
on DGV i can see at all the string[] properties
on the datagrid i can see them but as property type and not as a value
image example:
http://farm6.staticflickr.com/5519/10725217114_226ddd96c7_m.jpg
my collection have millions of rows, so i need an easy to process solution.
thank you all for the help
newMTE is a collection itself and your string[] are collection of items too (string array).
You can use something like Grouping or Show Row Details to show subrows of a row.
Examples here:
http://www.wpftutorial.net/DataGrid.html

C# XmlSerializer has error while reflecting type

To transfer data, I'm using XmlSerializer. But I get a runtime error at following line:
XmlSerializer serializer = new XmlSerializer(typeof(Packets.Wrapper));
The error is "Additional information: Error reflecting type 'Packets.Wrapper'.". MSDN says that I have to use an empty contructor, but it doesn't fix the error.
The class looks like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace Packets
{
[Serializable]
public class Wrapper
{
int _sID = 0;
int _sSession = 0;
PacketType _sType = PacketType.None;
AuthRequest _sAuthRequest = null;
AuthResponse _sAuthResponse = null;
ProxyRequest _sProxyRequest = null;
ProxyResponse _sProxyResponse = null;
public Wrapper()
{
}
public int ID
{
get { return _sID; }
set { _sID = value; }
}
public int Session
{
get { return _sSession; }
set { _sSession = value; }
}
public PacketType Type
{
get { return _sType; }
set { _sType = value; }
}
public AuthRequest AuthRequest
{
get { return _sAuthRequest; }
set { _sAuthRequest = value; }
}
public AuthResponse AuthResponse
{
get { return _sAuthResponse; }
set { _sAuthResponse = value; }
}
public ProxyRequest ProxyRequest
{
get { return _sProxyRequest; }
set { _sProxyRequest = value; }
}
public ProxyResponse ProxyResponse
{
get { return _sProxyResponse; }
set { _sProxyResponse = value; }
}
}
[Serializable]
public enum PacketType
{
AuthRequest,
AuthResponse,
ProxyRequest,
ProxyResponse,
None
}
[Serializable]
public enum AuthResult
{
Accepted,
Denied,
Error
}
[Serializable]
public enum ProxyAction
{
Send,
Response,
Connect,
Close
}
[Serializable]
public enum ProxyResult
{
Connected,
Sent,
Revieved,
Error
}
[Serializable]
public class AuthRequest
{
string username = null;
string password = null;
public AuthRequest()
{
}
public string Username
{
get { return username; }
set { username = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
}
[Serializable]
public class AuthResponse
{
AuthResult authResult = AuthResult.Denied;
public AuthResponse()
{
}
public AuthResult AuthResult
{
get { return authResult; }
set { authResult = value; }
}
}
[Serializable]
public class ProxyRequest
{
ProxyAction _sAction;
string _sIP = null;
int _sPort = 0;
TcpClient _sClient = null;
public ProxyRequest()
{
}
public ProxyAction Action
{
get { return _sAction; }
set { _sAction = value; }
}
public string IP
{
get { return _sIP; }
set { _sIP = value; }
}
public int Port
{
get { return _sPort; }
set { _sPort = value; }
}
public TcpClient Client
{
get { return _sClient; }
set { _sClient = value; }
}
}
[Serializable]
public class ProxyResponse
{
public ProxyResult _sResult = ProxyResult.Error;
public StringBuilder _sError = new StringBuilder();
public StringBuilder _sRecieved = new StringBuilder();
public TcpClient _sClient = null;
public ProxyResponse()
{
}
public ProxyResult Result
{
get { return _sResult; }
set { _sResult = value; }
}
public StringBuilder Error
{
get { return _sError; }
set { _sError = value; }
}
public StringBuilder Recieved
{
get { return _sRecieved; }
set { _sRecieved = value; }
}
public TcpClient Client
{
get { return _sClient; }
set { _sClient = value; }
}
}
}
I hope you can help me and thank you for your time.
I got it.
TcpClient isn't serializable.

Categories

Resources