473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Expose a struct ?

I have a web service used for rating images (as well as storing and
retrieving them), but when retrieving the comments (and ratings) related to
an image i need to retrieve an array (or list) with multipls fields. Is it
possible to expose a struct (and return an arraylist of this struct) or
similar effect? Or is there a better way to do this?
Dec 11 '05 #1
4 2198
Hi Michael,

Framework1.1 is unable to serialize quite a few forms of lists, this
includes arrays and datatables. Wrapping it in something that can be
serialized is usually a good solution, e.g.: To send a single datatable I
put it in a dataset and simply take it out again on the other side.

Framework 2.0 elegedly solves this problem.

HTH,
Cyr
Dec 12 '05 #2
GCR
Datasets are not really the solution, even if you are using typed datasets -
the interoperability with consumers on other platforms is not guaranteed!
You should design your exchanged datataypes so that you can deserialize them
into collections or arrays. Per default, if you specify something like:
<xs:element name="someName" type="xs:string" minOccurs="0"
maxOccurs="unbounded" /> then the types generated by wsdl.exe or xsd.exe (or
even by the Visual Studio web reference wizard) are arrays. You can change
these defaults to be somekind of collections, inheriting from CollectionBase.

"Cyr1dian" wrote:
Hi Michael,

Framework1.1 is unable to serialize quite a few forms of lists, this
includes arrays and datatables. Wrapping it in something that can be
serialized is usually a good solution, e.g.: To send a single datatable I
put it in a dataset and simply take it out again on the other side.

Framework 2.0 elegedly solves this problem.

HTH,
Cyr

Dec 12 '05 #3
I am new to .NET (and programming in general) therefore unfamiliar with
wrapping :-) I hate to have a n00b attitude and ask for a code example, but
it would really help :-)

"Cyr1dian" wrote:
Hi Michael,

Framework1.1 is unable to serialize quite a few forms of lists, this
includes arrays and datatables. Wrapping it in something that can be
serialized is usually a good solution, e.g.: To send a single datatable I
put it in a dataset and simply take it out again on the other side.

Framework 2.0 elegedly solves this problem.

HTH,
Cyr

Dec 12 '05 #4
GCR
Ok, start with the serialized xml form: you can write the multiple field list
as a list of elements with attributes, like this one:

<resultList xmlns="http://sampleschema.com/SerializedData.xsd">
<listItem id="0">zero</listItem>
<listItem id="1">one</listItem>
<listItem id="2">two</listItem>
<listItem id="3">three</listItem>
<listItem id="4">four</listItem>
<listItem id="5">five</listItem>
<listItem id="6">six</listItem>
<listItem id="7">seven</listItem>
<listItem id="8">eight</listItem>
<listItem id="9">nine</listItem>
</resultList>

The schema for this list looks like this:

<xs:schema id="resultList"
targetNamespace="http://sampleschema.com/SerializedData.xsd"
xmlns:mstns="http://sampleschema.com/SerializedData.xsd"
xmlns="http://sampleschema.com/SerializedData.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="resultList">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="listItem">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" form="unqualified" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Now you can generate the C# classes that serialize like this using the
command "xsd.exe SerializedData.xsd /c", and you get this code:

using System.Xml.Serialization;

[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://sampleschema.com/SerializedData.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://sampleschema.com/SerializedData.xsd", IsNullable=false)]
public class resultList {
[System.Xml.Serialization.XmlElementAttribute("list Item")]
public resultListListItem[] Items;
}
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://sampleschema.com/SerializedData.xsd")]
public class resultListListItem {
[System.Xml.Serialization.XmlAttributeAttribute()]
public string id;
[System.Xml.Serialization.XmlTextAttribute()]
public string Value;
}

As you can see, the resultList object contains an array of resutListItem
objects, each containing an id attribute and the value.
Of course, you can create another serialized structure, as you need, but
take care of the schema validity, or else you will not be able to generate
the classes using xsd.exe.
Dec 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MP | last post by:
Hello, I am trying to write a class that will expose some properties. One of the property is extracted from a SQL database and can be NULL or some integer value. Is there a elegant way of...
2
by: Teis Draiby | last post by:
What does it take to expose MC++ functions to C#? (Component/Assembly/?/?) I just ordered books on the topic at Amazon but just I can't wait getting started. I would be very happy to get some clues...
2
by: maxim | last post by:
Hi, I have a Class in C# that exposes property from System.Uri type. I want to access this property from classic Visual Basic. public class TestClass {
1
by: Hank | last post by:
I am writing a windows service in C#.NET which will manage image capturing devices, when client connects to the service, at some point the service need to expose a device dialog to the client for...
3
by: Vera | last post by:
I built a class in VB.NET that has an overloaded constructor. It can either accept nothing, a string or an object Public Sub New( MyBase.New( End Su Public Sub New(ByVal strName As String...
0
by: Taja | last post by:
Hi, I'm looking for a solution which can expose query's via webservice, with the following approach: 1. Administration part which allows the user to connect to a datasource and define some...
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
3
by: Miguel Ferreira via .NET 247 | last post by:
Hi ! I have developed a class Library with several classes and methods. Its working fine with a windows forms test application, but now i need to create a webservice that will expose those...
1
by: spranks | last post by:
Hello How do I expose a struct in a COM dll created using ATL/ C++. I am familiar with adding an interface using ATL simple object, but am not able to figure out how to expose a struct that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.