By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,952 Members | 1,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,952 IT Pros & Developers. It's quick & easy.

Pass in XML to WebService Method?

P: n/a
I have the following xml Schema:

“<?xml version="1.0" encoding="Windows-1252"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Document">
<xs:complexType>
<xs:sequence>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="Folder">
<xs:complexType>
<xs:sequence>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Folder" />
<xs:element ref="Document" />
</xs:sequence>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>”

I want to pass xml documents into a web service that conforms to this
schema. What I have tried to do is use the xsd /c tool to produce a class
based on the schema then have a method definition as follows:

[WebMethod]
public bool test(Folder test)
{
return true;
}

This only allows me to pass in a folder containing one document. The schema
allows for each folder to contain any number of folders or documents. What
can I do to enable this to work?

Thanks

Jan 28 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello Nick,

According to the XML Schema you mentioned, I have performed some test on my
local side. It seems the XSD tool will generate the following class
(through xsd.exe /classes schamefile). And the generated Folder class
contains a "Document" and a "Folder1" property. However, both of the two
properties are of Array type. So you can add multiple Documents and Folders
instance as children of a Folder instance. This doesn't violate the XSD
schema you provided. Is this what you get in your test project also?

===================
public partial class Folder {

private Folder[] folder1Field;

private Document[] documentField;

private string nameField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Fold er")]
public Folder[] Folder1 {
get {
return this.folder1Field;
}
set {
this.folder1Field = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Docu ment")]
public Document[] Document {
get {
return this.documentField;
}
set {
this.documentField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
}

============================
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jan 29 '07 #2

P: n/a
Thanks for replying. That is exactly what I get with the XSD tool. My issue
is with using the following web service with a windows forms application:
“[WebMethod]
public bool test(Folder test)
{
return true;
}”
By creating a new windows forms project and adding a web reference to this
service, I am unable to pass in a folder that contains multiple sub folders:
“WebReference.Service wr = new WebReference.Service();

WebReference.Folder Folder1 = new WebReference.Folder();”
How would I create sub folders / documents?

Thanks
"Steven Cheng[MSFT]" wrote:
Hello Nick,

According to the XML Schema you mentioned, I have performed some test on my
local side. It seems the XSD tool will generate the following class
(through xsd.exe /classes schamefile). And the generated Folder class
contains a "Document" and a "Folder1" property. However, both of the two
properties are of Array type. So you can add multiple Documents and Folders
instance as children of a Folder instance. This doesn't violate the XSD
schema you provided. Is this what you get in your test project also?

===================
public partial class Folder {

private Folder[] folder1Field;

private Document[] documentField;

private string nameField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Fold er")]
public Folder[] Folder1 {
get {
return this.folder1Field;
}
set {
this.folder1Field = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Docu ment")]
public Document[] Document {
get {
return this.documentField;
}
set {
this.documentField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
}

============================
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
Jan 29 '07 #3

P: n/a
From the generated class defintion of Folder, it has a Folder1 property of
type Folder[], and a Document property of type Document[].

Say you want to pass the contents of C.

WebReference.Folder myCDrive = new WebReference.Folder();

myCDrive.Folder1 = GetSubDirs("c");
myCDrive.Documents = GetFiles("c");

Where GetSubDirs() is a helper method, using System.IO.Directory class to
get directories, and transform the lot to WebReference.Folder[], and same
for GetFiles().

So now the myCDrive object, which is a top level view of the C directory,
has all subdirs and documents in that folder.

Use recursive directory listing code to populate all the subdirs down to a
specified nesting level if necessary.

Ron

"nickname" <ni*******@newsgroups.nospamwrote in message
news:1C**********************************@microsof t.com...
Thanks for replying. That is exactly what I get with the XSD tool. My
issue
is with using the following web service with a windows forms application:
"[WebMethod]
public bool test(Folder test)
{
return true;
}"
By creating a new windows forms project and adding a web reference to this
service, I am unable to pass in a folder that contains multiple sub
folders:
"WebReference.Service wr = new WebReference.Service();

WebReference.Folder Folder1 = new WebReference.Folder();"
How would I create sub folders / documents?

Thanks
"Steven Cheng[MSFT]" wrote:
>Hello Nick,

According to the XML Schema you mentioned, I have performed some test on
my
local side. It seems the XSD tool will generate the following class
(through xsd.exe /classes schamefile). And the generated Folder class
contains a "Document" and a "Folder1" property. However, both of the two
properties are of Array type. So you can add multiple Documents and
Folders
instance as children of a Folder instance. This doesn't violate the XSD
schema you provided. Is this what you get in your test project also?

===================
public partial class Folder {

private Folder[] folder1Field;

private Document[] documentField;

private string nameField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Fold er")]
public Folder[] Folder1 {
get {
return this.folder1Field;
}
set {
this.folder1Field = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Docu ment")]
public Document[] Document {
get {
return this.documentField;
}
set {
this.documentField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
}

============================
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

================================================= =

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights

Jan 29 '07 #4

P: n/a
Thanks for Ron's input.

Hi Nick,

As Ron mentioned, you can provide multiple subfoldes to the "Folder1"
property, and multiple documents to the "Document" property. e.g

==================
static void SimpleTest()
{
TestService.Service ts = new Service();

Folder folder = new Folder();
folder.name = "root_folder1";

Folder[] subfolders = new Folder[3];
subfolders[0] = new Folder();
subfolders[1] = new Folder();
subfolders[2] = new Folder();

folder.Folder1 = subfolders;

Document[] documents = new Document[3];
documents[0] = new Document();
documents[1] = new Document();
documents[2] = new Document();

folder.Document = documents;
string ret = ts.SendFolder(folder);
..........
}
=====================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Jan 30 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.