So I have an application that uses a webservice, On the UI side the user picks a table which sends a request across the web to my webservice to return the fields of this table.
So after this request is accomplished I have, on the webservice side a series of Name,Type Pairs that I need to serialize and send back to my client. I could use a List(of String()) to send the values back but I want to use a List(of Custom_Class) instead because later I have to do this on a much larger scale and I want to learn on this simpler version.
Now I know from my research that I can create a class from an .XSD document so what I’m thinking I should do is convert this class into a .XSD and somehow send that with my request to the WebService so that it can use that .XSD to create a class dynamically at runtime, instantiate that class into objects, fill those objects with the result set, bundle it into a strongly typed List(of ReturnFields), serialize that into XML, send it back to my client, Deserialize it back and display it for him.
So 2 questions:
1. Am I on the right track here or am I going about this all the wrong way.
2. How do I pass the .XSD schema to my Webservice so it can use it to create the class on the server side?
————–EDIT———–
So based on pMartin’s input I’m revising this question a bit.
So below is my code as it stands now.
I have a “Fields” Class Living on my Library Layer
Public Class Fields
Private Field_Name As String
Private Field_Type As System.Type
Public Sub New()
End Sub
Protected Overrides Sub Finalize()
End Sub
Property Name() As String
Get
Return Field_Name
End Get
Set(ByVal value As String)
Field_Name = value
End Set
End Property
Property Type() As System.Type
Get
Return Field_Type
End Get
Set(ByVal value As System.Type)
Field_Type = value
End Set
End Property
End Class
This get’s used in my library by the following code.
Public Function Get_List_Of_Fields(ByVal Table_Name As String, ByVal Database_Name As String) As List(Of Fields)
Dim List_Of_Fields As New List(Of Fields)
Dim DataModel As MetaModel = Get_Datamodel(Database_Name)
Dim Data_Table = (From DataTable In DataModel.GetTables Where DataTable.TableName = Table_Name).FirstOrDefault
For Each Field In Data_Table.RowType.DataMembers
Dim Fields_Obj As New Fields
Fields_Obj.Name = Field.Name
Fields_Obj.Type = Field.Type
List_Of_Fields.Add(Fields_Obj)
Next
Return List_Of_Fields
End Function
Which Returns to my Webservice (.ASMX)
<WebMethod()> _
Public Function Get_List_of_Fields(ByVal Table_Name As String, ByVal Database_Name As String) As List(Of Fields)
Return _DynaLib.Get_List_Of_Fields(Table_Name, Database_Name)
End Function
Which returns to my Client
‘This is where my error is on this “return” line
Imports Dynamic_Charting.DynamicReference
Private _DynamicService As New DynamicServiceSoapClient
Public Function Get_List_of_Fields(ByVal Table_name As String, ByVal Database_Name As String) As List(Of Fields)
Return _DynamicService.Get_List_of_Fields(Table_name, Database_Name)
End Function
It is here that I have my error. I get the following Error.
Error 11
Value of type ‘1-dimensional array of Dynamic_Charting.DynamicReference.Fields’ cannot be converted to
‘System.Collections.Generic.List(Of Dynamic_Charting.DynamicReference.Fields)’.
I don’t see any reason that you need to pass an XML schema back and forth between the client and the web service. If you want to use a custom class to send back your output data, you can just set your custom class as the return type on the web service method.
Essentially, you would have a definition like this for your web service method (assuming that you also have a class called InputFields to capture the data about the table that the user picked):