Simple Webservice Request

H

Herb

I'm trying to create a webservice that will return a table of items to the
caller. This seems like a pretty basic concept but since I am new to
Webservices it's turning out to be a task.

Here is what I want the XML file to look like:
<Media>
<title>Moonrock</title>
<stream>mms://...</stream>
<title>Earthrock</title>
<stream>mms://...</stream>
</Media>

Here is the code from my .NET 2.0 project:
<System.Web.Services.WebService(Namespace:="http://xxx.com/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class AVService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function ReturnVideoList() As Stream
Dim xmlStream As New MemoryStream
Dim writer As New XmlTextWriter(xmlStream, Encoding.UTF8)
writer.Formatting = Formatting.Indented
writer.WriteStartElement("Media")
writer.WriteElementString("Title", "California")
writer.WriteElementString("Stream",
"mms://www.themediapreserveav.com/videos/California.wmv")
writer.WriteEndElement()
writer.WriteFullEndElement()
writer.Flush()
xmlStream.Flush()
xmlStream.Position = 0
ReturnVideoList = xmlStream
End Function

When I test this code and click on the ReturnVideoList hyperlink that
displays, then click the Invoke button I get an HTTP 500 Internal Server
error.

Can someone please point me in the right direction toaccomplish this goal.

Thanks, Herb
 
S

Steven Cheng [MSFT]

Hi Herb,

from your description, you're going to return some XML format to client
through your ASP.NET webservice ,correct?

Based on my experience, for ASP.NET webservice, if you return some
strong-type object to client, it will use XML serialziation to serialize
the object into xml format content.

#XML Serialization in the .NET Framework
http://msdn.microsoft.com/en-us/library/ms950721.aspx

However, if you only want to transfer a normal plain xml document to
client-side, I think you can use the following approach:

** instead of create the XML document via string(concatenating), you should
use the XmlDocument class to construct the XML content and return the
XMLdocument. MemoryStream is not suitable here since it is not a
serialable object.

Here are some reference articles introcuding use XMLDocument to construct a
in-memory XML document and save it to file or return via webservice method:

#Create a New XML File Using XmlDocument
http://www.devx.com/tips/Tip/21168

#HOW TO: Use XmlDocument Elements When Passed to or Returned from
WebMethods by Using Visual C# .NET
http://support.microsoft.com/kb/330600

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
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.
--------------------
From: =?Utf-8?B?SGVyYg==?= <[email protected]>
Subject: Simple Webservice Request
Date: Fri, 30 May 2008 13:34:00 -0700
I'm trying to create a webservice that will return a table of items to the
caller. This seems like a pretty basic concept but since I am new to
Webservices it's turning out to be a task.

Here is what I want the XML file to look like:
<Media>
<title>Moonrock</title>
<stream>mms://...</stream>
<title>Earthrock</title>
<stream>mms://...</stream>
</Media>

Here is the code from my .NET 2.0 project:
<System.Web.Services.WebService(Namespace:="http://xxx.com/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1
_1)> _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top