Serialize Generic XML Data Across WCF Web Service Requests?
Jun 1, 2009
I've got a web app that sends a request to a WCF service. The WCF service gets a LINQ resultset (anon. ilist) and sends that in reply, back to the web app.In order to get it working quickly, inside the WCF app, i'm using copytodatatable and sending it to my web app in a DataSet.
My web app then takes the DataSet and writes it to xml, some xslt is performed and the resulting data is shown on screen. Perfect.
I'm still (relatively) new to WCF. I understand that sending DataTables/DataSets is a bit cumbersome. The web app wants the data in xml format (for the xslt operation), so I figured I'd get the WCF web service to do the DataTable -> xml work for me, and simply reply with a nice XmlDocument to the client webapp.However a XmlDocument cannot be serialized.
What's the best way of sending the XML data down to the client over wcf?
I am trying to serialize a class that contains a generic list, and I am finding it all works with the exception of the generic list property. That is to say the other properties are serialized fine and no error is produced.
I have in the past serialized an arraylist - but I thought it was possible to do a generic list in the same way.
Am I missing something or is it not possible to serialize/deserialize a generic list - I have read mixed comments on this..
The relevant parts of the class that gets serialized is defined as..
<XmlInclude(GetType(cConfigUser)), _ Serializable(), XmlRoot(ElementName:="Config")> _ Public Class cConfig
I want to download xsd specifications from a web service and automatic converting (serialize) these schemas to classes (visual studio - vb.net). If the organization that is responsible for the xsd schemas alter them in a way that only my class corresponding to the xsd have to be altered (not the rest of my code) I would like to automatic update my xsd corresponding class.
I use vs2010. What I want to do is: call a web service where I can send in an input parameter to the service which specifies the xsd I want to retrieve (the service is GetShemaDefenition and returns an object with the schema specification in a string property of the object). I den have to read the xsd string from the string property and convert this to a class representation of this xsd specification. Is it possible to do this automatically? I have done this manually by using xsd.exe. If the owner organization of the xsd has altered the xsd specification, I have to test if there is a new specification, and if there is I have to build a new class representation of this xsd? Is it possible to do what I want? And how would I know if it has been a big change in the xsd which also affect other parts of my code, not just the class representation of the xsd?
Update:I use one web service where one of the properties is a string. The string is an XML inside a CDATA block. The organization which provides the web service will not pares the xml inside the CDATA block but instead forward this to another organization that will use the xml data. The organization which uses the xml data specifies the xsd schem that I have to follow to generate my xml correct. This is the xsd schema I can get from another web service. I don't really understand what I can do with this xsd file from the web service. What can I do with it and why do I want to download it from the web service, when I can't use it automatically? Because I have to manually do the changes when the xsd changes I can easily download the xsd schema from the organization's home page and make the new class with xsd.exe.
I am looking into make a generic DB importing tool. As of now it is only targeting CSV's.Now I don't have much experience on this front but to make it useable with multiple files, I have pretty much set it up so it is reliant on a XML configuration file.I don't have any actual VB code as I am working on the XML format, but I just want to know what you guys think and if there is a better way to go about it.[code]So if the record to be import was suppose to be a entry date, name, and Food prefrence it would look like this: 1DA, 1S, 0S.This means there has to be a value other than null or a null string and then it would verify that it can be converted to a date, and so on and so forth.
My winforms application is consuming webservices that run on an older PHP server, which is why i often get an XML parsing error from the service class when i invoke its members.
how do I get to see the faulty XML so that I may correct it on the PHP server - the thrown exception clearly states the position of the error in the XML, but it doesn't help without the XML.
If a class is serialized and has events fired from it that are handled on a form you get the error "Form1 cannot be serialized" in c# you can use (to work around this):
Dim js As JavaScriptSerializer = New JavaScriptSerializer() dim jsonString as string jsonString=js.serialize(dt)
when it serialize the data table on the last line,it got an error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll Additional information: A circular reference was detected while serializing an object of type 'System.Globalization.CultureInfo'I even make the simplest datatable with only 1 column and 1 row, but it just won't serialize it?
I'm trying to serialize/deserialize data in vb. I've made a .dat file from a blank plain text file (not sure if this is suitable) which seems to connect ok, as do both the classes. Here's the
I have searched for an answer for a long time now, both generally ont he web and in several forums including this one. There are many people who asks this or similar qusetions, but the answers are often hard to understand, and quite often are answers to something other than what was asked from the beginning.I know that there are many skilled programmers out there, but most are not great teachers. So here is what I need: I have constructed a program in which the user can write values in textboxes, choose from lists (comboboxes) and make some choices by checking checkboxes. The data in the lists comes from a database, but I don't think that is really relevant here. What I want is, when all the choices are made and when the textboxes, comboboxes and so on have data (text or numbers) in them, I want the user to be able to save this to a file (XML perhaps?).
To speak plainly and visualize this to you, think of a roleplaying game (RPG), and that you fill out a character form with details about your character. Of course you want to save all this, and at some point retrieve it to make changes when you level up. I am not all that stupid when it comes to programming, but I have never tried to do something like this. My applications have had a database engin behind the GUI, and all the saving was done in tables at the far end of everything. Now I want to save data to a file instead. I have tried to find books (or a good tutorial here on the web), but most answers are for C (++. #, etc), or else they are hard to understand.
Is there anyone here who can help me or point me in the right direction? I'm not asking you to do my work for me, but som examples that are valid and that will help me understand the process whould be nice. So far I have recieved good help here on this forum from nice people.
I'm trying to serialize a data structure and pass it to another report via parameter, and this line of code:
Dim s As New System.Xml.Serialization.XmlSerializer(GetType(System.Collections.HashTable))
Produces this error:
An error occurred during local report processing. The definition of the report '/myReport' is invalid. There is an error on line 22 of custom code: [BC30002] Type 'System.Xml.Serialization.XmlSerializer' is not defined.
How can I get around this? I have been able to use fully defined .NET classes in other lines of code, including the following:
Dim outStream As New System.IO.StringWriter()
and
Private colorMapping As New System.Collections.Hashtable()
We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.
In VB6, we were using structures in many places. As a part of introducing object oriented programming,
1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?
2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.
Public MustInherit Class Column Public ReadOnly Property ReturnSomethingUseful() As Object Get 'return something useful
[code]....
But this gives the following error:
Public Overrides Function ParseValue(sValue As String) As Boolean' cannot override 'Public Overridable Function ParseValue(sValue As String) As Object' because they differ by their return types.
I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.
I'm looking for a method for reading data from a txt file. The text file have this kind of structure (fixed length fields): 0000 AAAAAA BBBBBB CCCCCCCC 0000 JJJJJJ III RRRRRR 1111 XXXX YYYYYYYY ZZZZZZZZ 1111 WW PPPPPPPP ZZZZZZZZ 1111 XXXX YYYYYYYY ZZZZZZZZ 2222 XXXX YYYYYYYY ZZZZZZZZ ...
I have to get them in groups by first field, in some kind of list of dictionary lists or something like this. For this particular example the solution would be: id(list): 0000,1111,2222..... (content)List: 0000 field1(list): AAAAAA,JJJJJJ field2(list): BBBBBB,III field3(list): CCCCCCCC,RRRRRR (content)List: 1111 field1(list): XXXX,WW,XXXX field2(list): YYYYYYYY,PPPPPPPP,YYYYYYYY field3(list): ZZZZZZZZ,ZZZZZZZZ,ZZZZZZZZ (content)List: 2222 field1(list): XXXX... field2(list): YYYYYYYY... field3(list): ZZZZZZZZ...
Right now I have the the whole text stored in a list of strings (one per line).
i have a Windows service that is hosting a WCF service through net.tcp and this is working great. I have also created a WCF service application. I am trying to add the net.tcp service reference to the service application. Then I add it to the GAC that goes ok but if I try to RegAsm the WCF service application to allow it to be called from Server.CreateObject I get the error:
Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute.
It does not work. I have tried to call it through a class library but this does not work either as the end point is not set correctly.
I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]
Please forgive, I'm new to Silverlight and am still trying to wrap my head around data binding...
I have a generic list obtained from a class using LINQ. The list has 4 objects, each object consisting of a Letter property (string - A, B, C and D) and a corresponding Number property (integer - 1, 2, 3, and 4).
In Silverlight, I have a combobox control and a text block. I'm trying to figure out how to:
Bind the combobox to the generic list so that the letters populate the combobox.When the user selects a letter in the combobox (say C), the corresponding integer value (3 for this example) is displayed in the text block.
addressing the need for getting the bytes of an object. But I am wondering if there is an approach to calling BitConverter.GetBytes on a generic type where I know the type is a primitive (Int32, UInt16, etc).
Public Sub Foobar(Of T as Structure)() Dim x as T 'Assume T is declared as Int32 Dim y() as Byte y = System.BitConverter.GetBytes(x) End Sub
The above will throw your usual error:
Overload resolution failed because no accessible 'GetBytes' can be called with these arguments: 'Public Shared Function GetBytes(value As Double) As Byte()': Value of type 'T' cannot be converted to 'Double'. 'Public Shared Function GetBytes(value As Single) As Byte()': Value of type 'T' cannot be converted to 'Single'.
[code]....
One solution I think would work is a large Select Case calling GetType(), but that is horrendously slow (because of boxing) and looks ugly. I would think that since I call my higher level class with a primitive data type for T, that the compiler would be smart enough to figure it out, but I assume I am not providing enough information for it to derive what T's underlying value is at compile time for the invoked instances.
I am trying to create a list of a generic type in vb.net 2.0 framework. This is the generic type definition:
Public Class GenericParamMap(Of T) Public Sub New(ByVal pParamName As String, ByVal pPropValue As T) mParamName = pParamName
[Code]....
The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.
I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).
I'm tyring to pass a variable data type to a template class. Something like this:
frmExample = New LookupForm(Of Models.MyClass) 'Works fine
Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine frmExample = New LookupForm(Of SelectedType) 'Ba-bow! frmExample = New LookupForm(Of InstanceOfMyClass.GetType()) 'Ba-bow!
[Code].....
I'm assuming it's something to do with the template being processed at compile time but even if I'm off the mark there, it wouldn't solve my problem anyway. I can't find any relevant information on using Reflection to instance template classes either.
(How) can I create an instance of a dynamically typed repository at runtime?
I have a VB2008 application which can control a windows service i.e. start, stop, pause etc. This runs ok on a Windows XP machine but not on a Win 7 machine (message is - Service error cannot open <service name> service on computer '.') ( if I stop the UAC then it runs ok ). It seems to be a rights issue,
I have a website and say a user comes along and fills out the form with bogus data. Then after he fills it out, he enters another one and another one and another one of bogus data. He's basically just trying to clog up the data base.
How is the best way to combat this? Would it make sense to when they submit the data track the IP address?
I'm writing a web crawler for a specific site. The application is a VB.Net Windows Forms application that is not using multiple threads - each web request is consecutive. However, after ten successful page retrievals every successive request times out. I have reviewed the similar questions already posted here on SO, and have implemented the recommended techniques into my GetPage routine, shown below: