C# - Web Service

Hi

I have found an article "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service02112003.asp" and I tried to used the 3rd implementation which returns clear WSDL to the user. But it always thrown an exception "Server was unable to process request. --> There was an error generating the XML document. --> Specified cast is not valid." Anyone has idea about this? or else is there anyway to make clear understandable WSDL to the user.

-Shan
LVL 2
prashanthanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
How did you try to implement this?

Bob
0
prashanthanAuthor Commented:
private class Items
{
    public int ItemNumber;
    public string Description;
    public Decimal Price;
}

[WebMethod()]
[return: XmlElement(typeof(Items[]))]
public XmlDataDocument GetTypedXmlDataDocument()
{
    sqlDataAdapter1.Fill(typedDataSet1);
    XmlDataDocument dataDoc
        = new XmlDataDocument(typedDataSet1);
    return dataDoc;
}

The method XmlDataDocument throws that exception. It is the example taken from the above microsoft link. For more details, check it.

-Shan
0
Bob LearnedCommented:
I don't see how you can cast an XmlDataDocument as an array of Items, so that exception makes sense.  I will have to read the article more closely, since that return attribute doesn't make sense.

Bob
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Bob LearnedCommented:
Actually, I see this type definition, but I don't see where you are supposed to use it:

<s:complexType name="ArrayOfItems">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="unbounded"
        name="Items" nillable="true" type="s0:Items" />
    </s:sequence>
</s:complexType>
<s:complexType name="Items">
  <s:sequence>
    <s:element minOccurs="1" maxOccurs="1"
        name="ItemNumber" type="s:int" />
    <s:element minOccurs="0" maxOccurs="1"
        name="Description" type="s:string" />
    <s:element minOccurs="1" maxOccurs="1"
        name="Price" type="s:decimal" />
  </s:sequence>
</s:complexType>

Bob
0
dabitbolCommented:
Hi,

2 things this  bit of code:

<s:complexType name="ArrayOfItems">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="unbounded"
        name="Items" nillable="true" type="s0:Items" />
    </s:sequence>
</s:complexType>
<s:complexType name="Items">
  <s:sequence>
    <s:element minOccurs="1" maxOccurs="1"
        name="ItemNumber" type="s:int" />
    <s:element minOccurs="0" maxOccurs="1"
        name="Description" type="s:string" />
    <s:element minOccurs="1" maxOccurs="1"
        name="Price" type="s:decimal" />
  </s:sequence>
</s:complexType>

is an XML Schema (or a typed DataSet) you use create a schema in VS.Net (Add New Item) and work with the XML. This will create the the typedDataSet you see here:


[WebMethod()]
[return: XmlElement(typeof(Items[]))]
public XmlDataDocument GetTypedXmlDataDocument()
{
    sqlDataAdapter1.Fill(typedDataSet1);
    XmlDataDocument dataDoc
        = new XmlDataDocument(typedDataSet1);
    return dataDoc;
}

Where typedDataset1 is an insntance of that class

good luck
0
Bob LearnedCommented:
I am having difficulty seeing the benefit to all this code, and that article.  I had a friend look at it, and he didn't understand it either.  Are you looking to learn something, fix something, or streamline your code?

Bob
0
prashanthanAuthor Commented:
Im trying to built a web service based on W3C Standard. I need to write a method which is a Search the customer details from the database and returns the value as XML Format.

The major problem is, When I return the XML data as a string or XMLDocument or XMLDataElement, the wsdl doesn't easily understandable by the end user. Also, the return XML structrue is doesn't described in the wsdl, so the customer need to execute the method to find the XML Structure.

I was searching in web to return a declared XML Structure in WSDL. In the above msdn link, it was said to be as it serialize the return XmlDocument as a class "Items". But the given example is not working.

Anyway, I have modified my logic to return the array of the class "Items" and now the wsdl has the return structure as the class "Items" which is easily understandble by the customer.

Do you know any logic to return this other than array of class ?

-Shan



0
Bob LearnedCommented:
No, I don't know.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dabitbolCommented:
Me neither
0
prashanthanAuthor Commented:
Anyway, Thanks Bob for spending your time for my issue.

-Shan
0
dabitbolCommented:
Well, thanks for my time too!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.