views:

157

answers:

1

I am creating a WCF Web Service in which one method (exposed in Service) return data in XML format as given below:

    public string QueryDirectoryEntry()
    {

        XmlDocument doc = new XmlDocument();
        doc.Load(@"c:\" + FILE_NAME);
        return doc.InnerXml;
    }

If the client call this method ther service return data in XML format , I want to bind this Xml in the datagridview control.

The XML data is actually contains the List.

class MyStruct
{
  Name..
  ID...
}

XML:

<root>
  <MyStruct>
    <Name>abc</Name>
    <ID>1</ID>
  </MyStruct>
  <MyStruct>
    <Name>abc</Name>
    <ID>2</ID>
  </MyStruct>
</root>

I want that data should be in XML so that every application can use this data either in C# or Java.

Please Help!!

+1  A: 

You should never return or manipulate XML as a string. Return it as XmlElement instead:

[ServiceContract]
public interface IReturnRealXml {
    [OperationContract]
    XmlElement QueryDirectoryEntry();
}

public class ReturnRealXmlNotStrings : IReturnRealXml {

    public XmlElement QueryDirectoryEntry()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(@"c:\" + FILE_NAME);
        return doc.DocumentElement;
    }
}
John Saunders
Thanks John for correcting me.. But can you please tell me how can I acheive the above said functionality ?
Ashish Ashu
I just _did_ show you. What else do you want to know?
John Saunders
I filled it out a bit. Is that better?
John Saunders
Sorry for the delayed response...Thanks for the reply John
Ashish Ashu