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 / August 2007

Tip: Looking for answers? Try searching our database.

Streams

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
valentin tihomirov - 19 Aug 2007 16:44 GMT
Noramlly, we have methods like:

   void execute(string login, string password, Stream inputStream) {

       if (login:password is wrong)
           throw new Exception("login failed");

       // forward or process the stream in chunks

   }

The WS framework does allow transferring streams (serialized objects, binary
data). However, the Stream class is not a valid web method parameter. WSE3
demonstrates how to (de-)serialize objects to/from XML stream:

// A service to get/put data from/to server
[WebService]
public class WebService1 : WebService {

   public WebService1() {}

   public XmlSerializableFile  GetFile(string fileName) {
       return  new XmlSerializableFile(fileName);
   }

   public void PutFile(XmlSerializableFile request) {
       Conlose.WriteLine("input stream has been buffered into " +
request.fileName);
   }

}

// An object serializable to file
[XmlSchemaProvider("GetMySchema")]
class XmlSerializableFile {

   public string fileName;

   XmlSerializableFile (string fileName) { this.fileName = fileName; }
   public XmlSchema GetSchema() { return null; }

   public static XmlQualifiedName GetMySchema(XmlSchemaSet xss) {
       return new XmlQualifiedName("base64Binary",
"http://www.w3.org/2001/XMLSchema");
   }

   /// restore the input stream data into a new file
   public void ReadXml(XmlReader r) {
       r.ReadStartElement(); // Read the open tag of the encapsulating
element

       fileName = TempFileName(); // create a new file
       using (FileStream fs = new FileStream(, FileMode.CreateNew)) {
           byte[] buf = new byte[1024];
           int numRead = 0;
           while ((numRead = reader.ReadContentAsBase64(buf, 0, 1024)) > 0)
                   fs.Write(buf, 0, numRead);
       }

       r.ReadEndElement(); // Read the close tag of the encapsulating
element
   }

   /// write a whole file into xml stream
   public void WriteXml(XmlWriter w) {
       using (FileStream fs = new FileStream(fileName, FileMode.Open,
FileAccess.Read)) {
           byte[] buf = new byte[1024];
           int numRead = 0;
           while ((numRead = fs.Read(buf, 0, 1024)) > 0)
               w.WriteBase64(buf, 0, numRead);
       }
   }

}

You see, the (de)serialization routine processes the whole stream (buffering
it into the memory or into a file). In result, all the featuring advantage
of streaming -- keeping the working set low -- is lost. Who needs such a
streaming? Pheahaps I'm just missing something and you know how to deliver a
stream right into a web method? I think it is normal to process a stream
depending on other method arguments.
John Saunders [MVP] - 19 Aug 2007 19:45 GMT
> Noramlly, we have methods like:
>
[quoted text clipped - 80 lines]
> you know how to deliver a stream right into a web method? I think it is
> normal to process a stream depending on other method arguments.

It may very well be normal to process streams in this manner. However, it is
not normal for the standard ASMX web service platform, as the basic
WSDL/XSD/WS-I BP-1 standards do not include streams of any kind.

Perhaps WCF can offer something like this.
Signature

John Saunders [MVP]

valentin tihomirov - 19 Aug 2007 20:01 GMT
> It may very well be normal to process streams in this manner. However, it
> is
> not normal for the standard ASMX web service platform, as the basic
> WSDL/XSD/WS-I BP-1 standards do not include streams of any kind.

It is just silly to stream between two large buffers. The feature of streams
is to replace the buffering with processing in parts.
John Saunders [MVP] - 19 Aug 2007 20:02 GMT
>> It may very well be normal to process streams in this manner. However, it
>> is
[quoted text clipped - 3 lines]
> It is just silly to stream between two large buffers. The feature of
> streams is to replace the buffering with processing in parts.

You are correct, of course.

This just proves that the basic Web Services standards are not appropriate
for streaming applications. Perhaps one of the WS-* standards covers that.
Signature

John Saunders [MVP]

valentin tihomirov - 20 Aug 2007 11:41 GMT
> This just proves that the basic Web Services standards are not appropriate
> for streaming applications. Perhaps one of the WS-* standards covers that.

Have you seen this:
Yasser Shohoud - "Web services and large content in .NET 2.0"
http://blogs.msdn.com/yassers/archive/2004/11/10/255212.aspx

WSE3.0 -- "How to: Stream Large Amounts of Data from a Web Service"
http://msdn2.microsoft.com/en-us/library/aa528818.aspx

???

Agreed on incompatibility between streams and web services, the microsoft
developments are deceptive.

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.