all groups > dotnet web services > january 2007 >
You're in the

dotnet web services

group:

Pass in XML to WebService Method?


Pass in XML to WebService Method? nickname
1/28/2007 7:36:02 AM
dotnet web services:
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
RE: Pass in XML to WebService Method? stcheng NO[at]SPAM online.microsoft.com
1/29/2007 12:58:31 PM
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("Folder")]
public Folder[] Folder1 {
get {
return this.folder1Field;
}
set {
this.folder1Field = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Document")]
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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



RE: Pass in XML to WebService Method? nickname
1/29/2007 1:36:00 PM
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


[quoted text, click to view]
Re: Pass in XML to WebService Method? RYoung
1/29/2007 4:19:55 PM
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

[quoted text, click to view]

Re: Pass in XML to WebService Method? stcheng NO[at]SPAM online.microsoft.com
1/30/2007 10:34:32 AM
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



AddThis Social Bookmark Button