|
|
|
start date: Sun, 19 Aug 2007 18:44:59 +0300,
posted on: microsoft.public.dotnet.framework.webservices
back
| Thread Index |
|
1
valentin tihomirov
|
|
2
John Saunders [MVP] john.saunders at trizetto.com
|
|
3
John Saunders [MVP] john.saunders at trizetto.com
|
|
4
valentin tihomirov
|
|
5
John Saunders [MVP] john.saunders at trizetto.com
|
|
6
valentin tihomirov
|
|
7
John Saunders [MVP] john.saunders at trizetto.com
|
|
8
valentin tihomirov
|
|
9
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:
|
Re: Streams
"valentin tihomirov" wrote in message
news:%23lmnXfn4HHA.4584@TK2MSFTNGP03.phx.gbl...
> 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.
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.
--
John Saunders [MVP]
Date:Sun, 19 Aug 2007 14:45:26 -0400
Author:
|
Re: Streams
"valentin tihomirov" wrote in message
news:%23lmnXfn4HHA.4584@TK2MSFTNGP03.phx.gbl...
> 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.
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.
--
John Saunders [MVP]
Date:Sun, 19 Aug 2007 14:45:26 -0400
Author:
|
Re: Streams
> 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.
Date:Sun, 19 Aug 2007 22:01:15 +0300
Author:
|
Re: Streams
"valentin tihomirov" wrote in message
news:ejxw8Mp4HHA.4184@TK2MSFTNGP06.phx.gbl...
>
>> 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.
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.
--
John Saunders [MVP]
Date:Sun, 19 Aug 2007 15:02:02 -0400
Author:
|
Re: Streams
> 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.
Date:Sun, 19 Aug 2007 22:01:15 +0300
Author:
|
Re: Streams
"valentin tihomirov" wrote in message
news:ejxw8Mp4HHA.4184@TK2MSFTNGP06.phx.gbl...
>
>> 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.
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.
--
John Saunders [MVP]
Date:Sun, 19 Aug 2007 15:02:02 -0400
Author:
|
Re: Streams
> 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.
Date:Mon, 20 Aug 2007 13:41:50 +0300
Author:
|
Re: Streams
> 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.
Date:Mon, 20 Aug 2007 13:41:50 +0300
Author:
|
|
|