Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C# - Web Service

Posted on 2006-03-28
11
Medium Priority
?
285 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:prashanthan
  • 5
  • 3
  • 3
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16324412
How did you try to implement this?

Bob
0
 
LVL 2

Author Comment

by:prashanthan
ID: 16325068
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16325354
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16325521
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
 
LVL 3

Expert Comment

by:dabitbol
ID: 16336766
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16342187
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
 
LVL 2

Author Comment

by:prashanthan
ID: 16375615
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 16393955
No, I don't know.

Bob
0
 
LVL 3

Expert Comment

by:dabitbol
ID: 16395138
Me neither
0
 
LVL 2

Author Comment

by:prashanthan
ID: 16395373
Anyway, Thanks Bob for spending your time for my issue.

-Shan
0
 
LVL 3

Expert Comment

by:dabitbol
ID: 16395695
Well, thanks for my time too!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question