473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Stream large file in WSE 3.0

Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installation. From sample provided (see below), I created WSE service side
code, but how can I consume stream returned by web method in my Web Form
application? I already configurated web.config of my web service by running
WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName, FileMode.Open)) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024)) 0)
{
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}
Oct 3 '06 #1
5 1539
Hi,

To my knowledge if you are to utilize the WSE MTOM then you got to send your
file as a byte[] not as a custom object at your will.. only the byte[] will
recognize by the Optimization machanism..

The GetFileResponseWrapper will pass olny the single public property it
has.. that is... FileName but in your case that also will not since it does
not have the setter part, since the object serialization/ deserialization is
needed the set/ get both to send it via SOAP successfully... I think you are
doing this very veyr wrong..

Since you said you are reading the help I will stop it here...

Nirosh.

object
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installation. From sample provided (see below), I created WSE service side
code, but how can I consume stream returned by web method in my Web Form
application? I already configurated web.config of my web service by
running WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName, FileMode.Open)) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName,
FileMode.CreateNew)) {
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024)) 0)
{
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}

Oct 3 '06 #2
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.htm
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwrote in message
news:Op**************@TK2MSFTNGP03.phx.gbl...
Hi,

To my knowledge if you are to utilize the WSE MTOM then you got to send
your file as a byte[] not as a custom object at your will.. only the
byte[] will recognize by the Optimization machanism..

The GetFileResponseWrapper will pass olny the single public property it
has.. that is... FileName but in your case that also will not since it
does not have the setter part, since the object serialization/
deserialization is needed the set/ get both to send it via SOAP
successfully... I think you are doing this very veyr wrong..

Since you said you are reading the help I will stop it here...

Nirosh.

object
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
>Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installation. From sample provided (see below), I created WSE service
side code, but how can I consume stream returned by web method in my Web
Form application? I already configurated web.config of my web service by
running WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName, FileMode.Open)) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName,
FileMode.CreateNew)) {
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}


Oct 3 '06 #3
I didn't read the link you gave but have a look here

http://msdn.microsoft.com/library/de...3f89f786bd.asp

and receiving part is even more simpler.. assuming that you know how to
create the proxy etc
byte[] response = serviceproxy.GetFile(fileName);
will let you access the binary stream received..

Nirosh.
Note: Please also refer to the sample given with the WSE 3.0.. check the
startup menu items.. under Microsoft WSE 3.0 >Document
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.htm
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwrote in message
news:Op**************@TK2MSFTNGP03.phx.gbl...
>Hi,

To my knowledge if you are to utilize the WSE MTOM then you got to send
your file as a byte[] not as a custom object at your will.. only the
byte[] will recognize by the Optimization machanism..

The GetFileResponseWrapper will pass olny the single public property it
has.. that is... FileName but in your case that also will not since it
does not have the setter part, since the object serialization/
deserialization is needed the set/ get both to send it via SOAP
successfully... I think you are doing this very veyr wrong..

Since you said you are reading the help I will stop it here...

Nirosh.

object
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
>>Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installation. From sample provided (see below), I created WSE service
side code, but how can I consume stream returned by web method in my Web
Form application? I already configurated web.config of my web service by
running WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName, FileMode.Open))
{
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName,
FileMode.CreateNew)) {
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}



Oct 3 '06 #4
Thanks, I already tried this solution before. My understanding is, it is not
stream, all dat will be read into memory then transfer to the other end
before we can use it.

Correct me if I am wrong.

"Champika Nirosh" wrote:
I didn't read the link you gave but have a look here

http://msdn.microsoft.com/library/de...3f89f786bd.asp

and receiving part is even more simpler.. assuming that you know how to
create the proxy etc
byte[] response = serviceproxy.GetFile(fileName);
will let you access the binary stream received..

Nirosh.
Note: Please also refer to the sample given with the WSE 3.0.. check the
startup menu items.. under Microsoft WSE 3.0 >Document
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.htm
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwrote in message
news:Op**************@TK2MSFTNGP03.phx.gbl...
Hi,

To my knowledge if you are to utilize the WSE MTOM then you got to send
your file as a byte[] not as a custom object at your will.. only the
byte[] will recognize by the Optimization machanism..

The GetFileResponseWrapper will pass olny the single public property it
has.. that is... FileName but in your case that also will not since it
does not have the setter part, since the object serialization/
deserialization is needed the set/ get both to send it via SOAP
successfully... I think you are doing this very veyr wrong..

Since you said you are reading the help I will stop it here...

Nirosh.

object
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installation. From sample provided (see below), I created WSE service
side code, but how can I consume stream returned by web method in my Web
Form application? I already configurated web.config of my web service by
running WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName, FileMode.Open))
{
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName,
FileMode.CreateNew)) {
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}


Oct 3 '06 #5
Ops!.. I have not understand the requirement..
ok you want the data to be read while they are transfering..is that the
requirement? but this method is something new to me.. let me do a small R&D
while you are replying..

Nirosh.

"Hardy Wang" <Ha*******@discussions.microsoft.comwrote in message
news:8D**********************************@microsof t.com...
Thanks, I already tried this solution before. My understanding is, it is
not
stream, all dat will be read into memory then transfer to the other end
before we can use it.

Correct me if I am wrong.

"Champika Nirosh" wrote:
>I didn't read the link you gave but have a look here

http://msdn.microsoft.com/library/de...3f89f786bd.asp

and receiving part is even more simpler.. assuming that you know how to
create the proxy etc
byte[] response = serviceproxy.GetFile(fileName);
will let you access the binary stream received..

Nirosh.
Note: Please also refer to the sample given with the WSE 3.0.. check the
startup menu items.. under Microsoft WSE 3.0 >Document
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.htm
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwrote in message
news:Op**************@TK2MSFTNGP03.phx.gbl...
Hi,

To my knowledge if you are to utilize the WSE MTOM then you got to
send
your file as a byte[] not as a custom object at your will.. only the
byte[] will recognize by the Optimization machanism..

The GetFileResponseWrapper will pass olny the single public property
it
has.. that is... FileName but in your case that also will not since
it
does not have the setter part, since the object serialization/
deserialization is needed the set/ get both to send it via SOAP
successfully... I think you are doing this very veyr wrong..

Since you said you are reading the help I will stop it here...

Nirosh.

object
"Hardy Wang" <ha*******@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
Hi all,
I am new to WSE 3.0, and currently reading the document shipped
with
installation. From sample provided (see below), I created WSE service
side code, but how can I consume stream returned by web method in my
Web
Form application? I already configurated web.config of my web service
by
running WSE 3.0 setting tool.

Thanks!
[WebMethod(BufferResponse = false)]
public GetFileResponseWrapper GetStream () {
String filePath = @"e:\temp\70ONEEL06COMP.pdf";
return new GetFileResponseWrapper(filePath);
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.CodeDom.Compiler;

/// <summary>
/// Summary description for GetFileResponseWrapper
/// </summary>
[XmlSchemaProvider("GetMySchema")]
public class GetFileResponseWrapper : IXmlSerializable, IDisposable {
private string _fileName;
private TempFileCollection tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponseWrapper ()
: this(null) {
}

public GetFileResponseWrapper (string fileName) {
_fileName = fileName;
// Manages the temp file that contains the file contents
// Dispose this wrapper to clean up temp files.
TempFileCollection tfc = new TempFileCollection();
}

#region Dispose logic
~GetFileResponseWrapper () {
Dispose(false);
}

public void Dispose () {
Dispose(true);
}

void Dispose (bool isDisposing) {
if (isDisposing && tfc != null)
tfc.Delete();
tfc = null;
}
#endregion

/// <summary>
/// The schema for the file contents node is actually just
/// base 64 binary data so return the qname of the schema
/// type directly.
/// </summary>
public static XmlQualifiedName GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedName("Base64Binary",
"http://www.w3.org/2001/XMLSchema");
}

/// <summary>
/// Always return null.
/// </summary>
public XmlSchema GetSchema () { return null; }

/// <summary>
/// Deserializes state out of an XmlReader
/// </summary>
public void ReadXml (XmlReader r) {
// Read the open tag of the encapsulating element
r.ReadStartElement();

//
// Read the binary data that represents the file contents
// into a temp file.
//
_fileName = tfc.AddExtension("fileContents", false);
ReadContentsIntoFile(r, _fileName);

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

/// <summary>
/// Serializes state into an XmlWriter
/// </summary>
public void WriteXml (XmlWriter w) {
using (FileStream fs = new FileStream(_fileName,
FileMode.Open))
{
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = fs.Read(buf, 0, 1024)) 0) {
w.WriteBase64(buf, 0, numRead);
}
}
}

void ReadContentsIntoFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(fileName,
FileMode.CreateNew)) {
if (r.CanReadBinaryContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAsBase64(buf, 0, 1024))
>
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedException();
}
}
}
}





Oct 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lee Gillie | last post by:
I am using Cryptography. You can encrypt or decrypt by providing an output stream as a parameter to the CryptoStream constructor. But I need byte arrays, as I am encrypting on the fly to a socket,...
4
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType(...
2
by: 7elephants | last post by:
I have the following piece of code to take data from one stream and put it into another... Int32 bufferSize = 100; Int32.TryParse(ConfigurationManager.AppSettings.ToString(), out bufferSize);...
5
by: Hardy Wang | last post by:
Hi all, I am new to WSE 3.0, and currently reading the document shipped with installation. From sample provided (see below), I created WSE service side code, but how can I consume stream returned...
5
by: Simon Rigby | last post by:
Hi folks, Apologies if this is not directly relevant but I was struggling to find a group with the appropriate context. So as my problem is in an aspx web site I thought I'd try here first....
7
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script...
0
by: =?Utf-8?B?am9obm55IHA=?= | last post by:
Hello - Ive created an HttpHandler for uploading binary files to an http compliant client (not a browser). These files I upload are fairly large around 256 MB. My code essentially chunks up the...
3
by: Jim Langston | last post by:
Is it possible in C++ to create some type of stream and pass something as an iobuf* such that fprintf uses? The reason is I am using some libraries that write to an open file pointer, but I want...
10
by: =?Utf-8?B?SnVhbg==?= | last post by:
Hi! I want to use ASP to download big files using ADODB.STREAM. It works very fine with files smaller than 80 MB. On the Webserver I can see that memory allocation and the process w3wp is...
1
by: Lambda | last post by:
As I know, when I use ifstream and ofstream to read and write file, it will use a stream buffer internally. How large is the stream buffer? If I want to write a large file, need I define a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.