DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Sun, 19 Aug 2007 18:44:59 +0300,    posted on: microsoft.public.dotnet.framework.aspnet.webservices        back       

Thread Index
  1    valentin tihomirov


Streams   
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.
Date:Sun, 19 Aug 2007 18:44:59 +0300   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us