473,651 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name, FileMode.Create New))
{
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024)) 0)
{
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}
Oct 3 '06 #1
5 2661
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 GetFileResponse Wrapper 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*******@hotm ail.comwrote in message
news:Oq******** ******@TK2MSFTN GP02.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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name,
FileMode.Create New)) {
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024)) 0)
{
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}

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.ht m
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwro te in message
news:Op******** ******@TK2MSFTN GP03.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 GetFileResponse Wrapper 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*******@hotm ail.comwrote in message
news:Oq******** ******@TK2MSFTN GP02.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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name,
FileMode.Creat eNew)) {
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}


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.Ge tFile(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*******@hotm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.ht m
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwro te in message
news:Op******** ******@TK2MSFTN GP03.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 GetFileResponse Wrapper 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/
deserializatio n 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*******@hotm ail.comwrote in message
news:Oq******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Hi all,
I am new to WSE 3.0, and currently reading the document shipped with
installatio n. 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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name,
FileMode.Crea teNew)) {
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}



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.Ge tFile(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*******@hotm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.ht m
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwro te in message
news:Op******** ******@TK2MSFTN GP03.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 GetFileResponse Wrapper 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*******@hotm ail.comwrote in message
news:Oq******** ******@TK2MSFTN GP02.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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name,
FileMode.Creat eNew)) {
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024)) >
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}


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*******@disc ussions.microso ft.comwrote in message
news:8D******** *************** ***********@mic rosoft.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.Ge tFile(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*******@hotm ail.comwrote in message
news:%2******* *********@TK2MS FTNGP05.phx.gbl ...
Thanks for your comment, I read this example from
ms-help://MS.WSE30.1033/WSE3.0/html/3e9ce678-2502-4847-9f13-5173896c9db5.ht m
or from MS MSDN
http://msdn.microsoft.com/library/de...73896c9db5.asp

Any idea what should I do?

"Champika Nirosh" <te**@tc.comwro te in message
news:Op******** ******@TK2MSFTN GP03.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 GetFileResponse Wrapper 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/
deserializatio n 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*******@hotm ail.comwrote in message
news:Oq******* *******@TK2MSFT NGP02.phx.gbl.. .
Hi all,
I am new to WSE 3.0, and currently reading the document shipped
with
installatio n. 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(Buffe rResponse = false)]
public GetFileResponse Wrapper GetStream () {
String filePath = @"e:\temp\70ONE EL06COMP.pdf";
return new GetFileResponse Wrapper(filePat h);
}
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;
using System.CodeDom. Compiler;

/// <summary>
/// Summary description for GetFileResponse Wrapper
/// </summary>
[XmlSchemaProvid er("GetMySchema ")]
public class GetFileResponse Wrapper : IXmlSerializabl e, IDisposable {
private string _fileName;
private TempFileCollect ion tfc = null;

public string FileName { get { return _fileName; } }

public GetFileResponse Wrapper ()
: this(null) {
}

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

#region Dispose logic
~GetFileRespons eWrapper () {
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 XmlQualifiedNam e GetMySchema (XmlSchemaSet xss) {
return new XmlQualifiedNam e("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.ReadStartElem ent();

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

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

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

void ReadContentsInt oFile (XmlReader r, string fileName) {
using (FileStream fs = new FileStream(file Name,
FileMode.Crea teNew)) {
if (r.CanReadBinar yContent) {
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = r.ReadContentAs Base64(buf, 0, 1024))
>
0) {
fs.Write(buf, 0, numRead);
}
} else {
throw new NotSupportedExc eption();
}
}
}
}





Oct 4 '06 #6

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

Similar topics

5
8049
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, and need to manage all socket traffic. My thought was a stateful call to my own Encrypt and Decrypt routines. That I would pass a MemoryStream to the CryptoStream constructor. But it appears that for each write CryptoStream does to my memory...
4
3563
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( CompensationPackage))).Deserialize(stream) But if I pass an XmlNodeReader to the deserializer it doesn't work:
2
11645
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); byte buffer = new byte;
5
2068
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. Please feel free to suggest a more relevent group. I have some code that I am using to build a stream (test text at this stage, although eventually will come from a database query). I want to have this available as a download without having to...
7
9880
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 streams the file if the user is authorised. This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB file presents the error message 'format error: not a pdf or corrupt'. Is there a file size limit, or a default that needs...
0
1193
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 file into small pieces and writes it to the response stream (using response.BinaryWrite.). I have the response property BufferOutput set to false and disabled all caching using SetCacheability(HttpCacheability.NoCache). Sessionstate is also...
3
5338
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 to use the data in my program without having to change the library source (all written in c). -- Jim Langston tazmaster@rocketmail.com
10
19331
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 running. After some time (more or less 2 minutes) I get a response timeout. Here is the code:
1
2226
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 stream buffer myself? In what situation, user-defined stream buffer is useful?
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.