Hi Reader forgive me but I have posted about this before, I've been asked to create a web serrvice. I have been provided with a schema of what the response will consist of. I have a number of questions as I've been investigating and trying to understand
some concepts regards web services but im gettting stuck.
Initially I just created a struct. of those elements of the schema. The struct was a couple of arrays which as I say represented the layout of the schema / XML that would be returned. I then populated the struct with the returned SQL stored procedure values
and returned the struct as my return value of the web service. The people who requested the web service tell me that the web service does not represent the defined schema they provided.
So Ive scrapped that and done thie following:-
1.) I have run the schema through XSD.exe, It has created a file of classes. I have added that file to my VS 2005 (ASMX) project.
2.) I have a SQL stored procedure wihich returns data mirroring the schema classes.
I think what I need to do now is return the dataset from the function that calls the stored procedure and populate the schema class. Would you agree this is the correct way to create a WS as defined by the requirements of a schema that has been provided
to me or am I missing something? I am now losing the will to live because I just keep going round in circles with my lack of knowledge.
Assuming this is correct. How can I populate the instantied schema class with my databse data and pass back?
I then have my class (created from the schema) This is the main part of the class which refers to other classes for the other structure to be returned:-
My schema class has the following:-
publicpartialclasstraceabilityResponse
{
privateobject[] itemsField;
privateItemsChoiceType[] itemsElementNameField;
///<remarks/>
[System.Xml.Serialization.
XmlElementAttribute("lensData",
typeof(LensData),
Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("prescriptionLeft",
typeof(Prescription),
Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("prescriptionRight",
typeof(Prescription),
Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("traceabilityError",
typeof(TraceabilityError),
Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlChoiceIdentifierAttribute("ItemsElementName")]
publicobject[] Items
{
get
{
returnthis.itemsField;
}
set
{
this.itemsField =
value;
}
}
///<remarks/>
[System.Xml.Serialization.
XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.
XmlIgnoreAttribute()]
publicItemsChoiceType[] ItemsElementName
{
get
{
returnthis.itemsElementNameField;
}
set
{
this.itemsElementNameField =
value;
}
}
}
So how would I then instantiate and populate this class with my data and return back through the web service?
Member
1 Points
11 Posts
WS with XSD
Sep 19, 2013 01:42 PM|Paul2012|LINK
Hi Reader forgive me but I have posted about this before, I've been asked to create a web serrvice. I have been provided with a schema of what the response will consist of. I have a number of questions as I've been investigating and trying to understand some concepts regards web services but im gettting stuck.
Initially I just created a struct. of those elements of the schema. The struct was a couple of arrays which as I say represented the layout of the schema / XML that would be returned. I then populated the struct with the returned SQL stored procedure values and returned the struct as my return value of the web service. The people who requested the web service tell me that the web service does not represent the defined schema they provided.
So Ive scrapped that and done thie following:-
1.) I have run the schema through XSD.exe, It has created a file of classes. I have added that file to my VS 2005 (ASMX) project.
2.) I have a SQL stored procedure wihich returns data mirroring the schema classes.
I think what I need to do now is return the dataset from the function that calls the stored procedure and populate the schema class. Would you agree this is the correct way to create a WS as defined by the requirements of a schema that has been provided to me or am I missing something? I am now losing the will to live because I just keep going round in circles with my lack of knowledge.
Assuming this is correct. How can I populate the instantied schema class with my databse data and pass back?
here is my web method:-
[WebMethod]
public traceabilityResponse Traceability(string authenticationCode, string vPlusCode)
I then have my class (created from the schema) This is the main part of the class which refers to other classes for the other structure to be returned:-
My schema class has the following:-
public partial class traceabilityResponse
{
private object[] itemsField;
private ItemsChoiceType[] itemsElementNameField;
/// <remarks/>
[System.Xml.Serialization.
XmlElementAttribute("lensData", typeof(LensData), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("prescriptionLeft", typeof(Prescription), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("prescriptionRight", typeof(Prescription), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlElementAttribute("traceabilityError", typeof(TraceabilityError), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.
XmlChoiceIdentifierAttribute("ItemsElementName")]
public object[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.
XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.
XmlIgnoreAttribute()]
public ItemsChoiceType[] ItemsElementName
{
get
{
return this.itemsElementNameField;
}
set
{
this.itemsElementNameField = value;
}
}
}
So how would I then instantiate and populate this class with my data and return back through the web service?
Please pleasse any help much appreciated.
Member
170 Points
102 Posts
Re: WS with XSD
Sep 27, 2013 02:19 AM|jjkk|LINK
Hi,
I'm not familiar with Web Service, but I found a article related with XML Schema Binding Support.
Please refer to the following article to search your answer.
http://msdn.microsoft.com/en-us/library/vstudio/sh1e66zd(v=vs.100).aspx