Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / January 2007

Tip: Looking for answers? Try searching our database.

Pass in XML to WebService Method?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nickname - 28 Jan 2007 15:36 GMT
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
Steven Cheng[MSFT] - 29 Jan 2007 12:58 GMT
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.

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



This posting is provided "AS IS" with no warranties, and confers no rights.
nickname - 29 Jan 2007 21:36 GMT
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

> Hello Nick,
>
[quoted text clipped - 84 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
RYoung - 29 Jan 2007 22:19 GMT
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

> Thanks for replying. That is exactly what I get with the XSD tool. My
> issue
[quoted text clipped - 101 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights
Steven Cheng[MSFT] - 30 Jan 2007 10:34 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.