SmartPhone (SP) and WebService Enhancements (WSE) with .NETcf - new DEVBUZZ tutorial

N

news

Hi all, So I had taken my first cut at WSE from the Compact Framework(.NETcf) many months ago (/cfWSE). Since then, I have gotten to do a lotmore Web Service (WS) work using the .NETcf. So I felt I was ready fora second attempt to raise the bar ... although this article isreally the third in a long running series. I could not continue the/cfWSE article because .NETcf was lacking theSystem.Security.Cryptography namespace; so that is why I wrote the follow up /spCrypt article.Now I can continue where I left off. http://www.devbuzz.com/content/zinc_smartphone_wse_pg1.asp -- Regards Derek Mitchell (e-mail address removed) .NET Compact Framework Tutorials: - http://www.devbuzz.com/content/init_compact_framework.asp eVB Tutorials: - http://www.devbuzz.com/content/init_starting_out.asp Pocket PC Development Forums: - http://forums.devbuzz.com/ Code Snippets: - http://www.devbuzz.com/content/code_snippet_list.asp
 
K

Katie

Hi,

I'm trying to get this solution (project files from the article) up and running but have run into a problem.

I have the web service "AnyService" running.

However, when i try to open the VS solution file (spWse.sln) i get an error "Unable to read the project file 'spWse.csdproj'".

VS did find the web service it just can't open the solution file.

Any ideas?
Hi all, So I had taken my first cut at WSE from the Compact Framework (.NETcf) many months ago (/cfWSE). Since then, I have gotten to do a lot more Web Service (WS) work using the .NETcf. So I felt I was ready for a second attempt to raise the bar ... although this article is really the third in a long running series. I could not continue the /cfWSE article because .NETcf was lacking the System.Security.Cryptography namespace; so that is why I wrote the follow up /spCrypt article. Now I can continue where I left off. http://www.devbuzz.com/content/zinc_smartphone_wse_pg1.asp -- Regards Derek Mitchell (e-mail address removed) .NET Compact Framework Tutorials: - http://www.devbuzz.com/content/init_compact_framework.asp eVB Tutorials: - http://www.devbuzz.com/content/init_starting_out.asp Pocket PC Development Forums: - http://forums.devbuzz.com/ Code Snippets: - http://www.devbuzz.com/content/code_snippet_list.asp
 
C

casey chesnut

this is just a guess ... do you have smartphone 2003 sdk installed?
try opening ppcWse.csdproj instead, it is in the spWse directory as well.
and you dont need the AnyService, that is just a unit test for {any} elements.
Thanks,
casey
Hi,

I'm trying to get this solution (project files from the article) up and running but have run into a problem.

I have the web service "AnyService" running.

However, when i try to open the VS solution file (spWse.sln) i get an error "Unable to read the project file 'spWse.csdproj'".

VS did find the web service it just can't open the solution file.

Any ideas?
Hi all, So I had taken my first cut at WSE from the Compact Framework (.NETcf) many months ago (/cfWSE). Since then, I have gotten to do a lot more Web Service (WS) work using the .NETcf. So I felt I was ready for a second attempt to raise the bar ... although this article is really the third in a long running series. I could not continue the /cfWSE article because .NETcf was lacking the System.Security.Cryptography namespace; so that is why I wrote the follow up /spCrypt article. Now I can continue where I left off. http://www.devbuzz.com/content/zinc_smartphone_wse_pg1.asp -- Regards Derek Mitchell (e-mail address removed) .NET Compact Framework Tutorials: - http://www.devbuzz.com/content/init_compact_framework.asp eVB Tutorials: - http://www.devbuzz.com/content/init_starting_out.asp Pocket PC Development Forums: - http://forums.devbuzz.com/ Code Snippets: - http://www.devbuzz.com/content/code_snippet_list.asp
 
K

Katie

Stil trying to send a binary file over SOAP using the code from devbuzz. I almost have it working :)



I get a "WebException" error when I call the code to send (echo) a binary file through the web service. The line the error occurs on is from the class "DimeServWrap.cs" the line is "object[] results = this.Invoke("Echo", new object[0]);" from the Echo routine.



Note that I am using the WSE SP1 web service example for dime. I have tested the web service with IE and with the client samples that come with WSE SP1. The web service works with the client sample and when browsed to with IE.



Also note that I have the debugger running on the web service to break on a line at the top of the web service echo method. However, the error I receive above occurs before the debugger steps into the webservice code for attachments.



My client code for the button click event is below.



***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?



Thanks



private void button1_Click(object sender, System.EventArgs e)

{

DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();

dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";



string myFile = @"\CC.jpeg";

FileInfo fi = new FileInfo(myFile);

FileStream fs = fi.OpenRead();

byte [] bytes = new byte[fs.Length];

int numRead = fs.Read(bytes, 0, (int)fs.Length);

fs.Close();

MemoryStream buffer = new MemoryStream(bytes);



bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(

"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),

"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);



dwServ.RequestAttachments.Add(attachment);



string outStr = dwServ.Echo();



foreach(bNb.Ws.Dime.DimeAttachment da in dwServ.ResponseAttachments)

{

StreamReader sr = new StreamReader(da.Stream, System.Text.Encoding.UTF8);

string strRes = sr.ReadToEnd();

outStr = outStr + "\r\n" + strRes;

}

MessageBox.Show(outStr, "success");

fs.Close();

}





this is just a guess ... do you have smartphone 2003 sdk installed?
try opening ppcWse.csdproj instead, it is in the spWse directory as well.
and you dont need the AnyService, that is just a unit test for {any} elements.
Thanks,
casey
Hi,

I'm trying to get this solution (project files from the article) up and running but have run into a problem.

I have the web service "AnyService" running.

However, when i try to open the VS solution file (spWse.sln) i get an error "Unable to read the project file 'spWse.csdproj'".

VS did find the web service it just can't open the solution file.

Any ideas?
Hi all, So I had taken my first cut at WSE from the Compact Framework (.NETcf) many months ago (/cfWSE). Since then, I have gotten to do a lot more Web Service (WS) work using the .NETcf. So I felt I was ready for a second attempt to raise the bar ... although this article is really the third in a long running series. I could not continue the /cfWSE article because .NETcf was lacking the System.Security.Cryptography namespace; so that is why I wrote the follow up /spCrypt article. Now I can continue where I left off. http://www.devbuzz.com/content/zinc_smartphone_wse_pg1.asp -- Regards Derek Mitchell (e-mail address removed) .NET Compact Framework Tutorials: - http://www.devbuzz.com/content/init_compact_framework.asp eVB Tutorials: - http://www.devbuzz.com/content/init_starting_out.asp Pocket PC Development Forums: - http://forums.devbuzz.com/ Code Snippets: - http://www.devbuzz.com/content/code_snippet_list.asp
 
C

casey chesnut

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
C

casey chesnut

//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
K

Katie

Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I get the error "Unable to read data from the transport connection". I tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I also made sure there was plenty of free memory on the ppc device (over 30meg free)



Could this be a web service timeout issue since the larger files inherently take more time or a limitation of another type perhaps with the file system?





//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
K

Katie

Casey,



Also... Can I create a new attachment (binary file) from within the web service echo method that can be returned to the ppc to create a local updated ppc file.



1. ppc binary file attachment sent to ws echo method...

2. echo method creates local file from attachment...

3. local file gets modified...

4. echo method creates new attachment from modified local file...

5. echo method returns new binary file attachment to ppc

6. ppc creates local modified file...



If I do this all from the same echo method call should I delete the incoming attachment before adding the outgoing attachment?



Also, do you recommend any books that cover web services and DIME?



By the way... This is awesome... 5 Meg transferred in 9 seconds! ;)


Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I get the error "Unable to read data from the transport connection". I tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I also made sure there was plenty of free memory on the ppc device (over 30meg free)



Could this be a web service timeout issue since the larger files inherently take more time or a limitation of another type perhaps with the file system?





//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
C

casey chesnut

the attachment size is likely an ASP.NET configuration,
and usually fails for anything over 4 megs.
see machine.config
<httpRuntime maxRequestLength="4096"

yes, the web service can return an attachment on the same call.
you do not need to delete the incoming attachment, which uses SoapRequest;
because the outgoing attachment will be on the SoapResponse.

there are only a couple books that even mention DIME.
Wiley - Web Service Enhancements
Addison - .NET Web Services
MsPress - Programming .NET Xml Web Services
I think there is an MsPress WSE book coming soon?

Casey,



Also... Can I create a new attachment (binary file) from within the web service echo method that can be returned to the ppc to create a local updated ppc file.



1. ppc binary file attachment sent to ws echo method...

2. echo method creates local file from attachment...

3. local file gets modified...

4. echo method creates new attachment from modified local file...

5. echo method returns new binary file attachment to ppc

6. ppc creates local modified file...



If I do this all from the same echo method call should I delete the incoming attachment before adding the outgoing attachment?



Also, do you recommend any books that cover web services and DIME?



By the way... This is awesome... 5 Meg transferred in 9 seconds! ;)


Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I get the error "Unable to read data from the transport connection". I tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I also made sure there was plenty of free memory on the ppc device (over 30meg free)



Could this be a web service timeout issue since the larger files inherently take more time or a limitation of another type perhaps with the file system?





//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
K

Katie

Casey,

That fixed the attachment size problem... thanks...

However when i try returning an attachment the PPC client gives an error. I get an "out of memory" error or "hexadecimal value 0x0C is an invalid character" error.

The echo code is below with notes in the "//CREATE OUTGOING ATTACHMENT" section.

I haven't added code to the client side to read the returned attachment yet. I'm just trying to get the return attachment added to the message.

Any ideas?

Oh.. i got the book. MS .NET XML WS... You're right only 3 pages on DIME :|

[WebMethod]
public string Echo()
{
// Reject any requests which are not valid SOAP requests
if (HttpSoapContext.RequestContext == null)
throw new ApplicationException("Only SOAP requests are permitted.");

//READ INCOMMING ATTACHMENT
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();

//CREATE LOCAL SERVER FILE FROM ATTACHMENT
MemoryStream m = new MemoryStream(ba);
FileStream f = new FileStream( @"c:\temp\temp.jpg", FileMode.Create);
m.WriteTo(f);
m.Close();
f.Close();

////JUST FOR TESTING --- WAIT FOR A FEW SECONDS FOR FILE TO BE COMMITED TO DISK
Thread.Sleep(5000);

//READ FILE INTO A STREAM FOR OUTGOING ATTACHMENT
string myFile = @"c:\temp\temp.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
numRead = fs.Read(bytes, 0, (int)fs.Length);
MemoryStream buffer = new MemoryStream(bytes);

//CREATE OUTGOING ATTACHMENT
// **** the next 2 lines cause an out of memory error
// **** if i remark out the lines the call completes correctly but without the response attachment
DimeAttachment attachment = new DimeAttachment("image/jpg",TypeFormatEnum.MediaType, buffer);
HttpSoapContext.ResponseContext.Attachments.Add(attachment);

fs.Close();
buffer.Close();
return str;
}
the attachment size is likely an ASP.NET configuration,
and usually fails for anything over 4 megs.
see machine.config
<httpRuntime maxRequestLength="4096"

yes, the web service can return an attachment on the same call.
you do not need to delete the incoming attachment, which uses SoapRequest;
because the outgoing attachment will be on the SoapResponse.

there are only a couple books that even mention DIME.
Wiley - Web Service Enhancements
Addison - .NET Web Services
MsPress - Programming .NET Xml Web Services
I think there is an MsPress WSE book coming soon?

Casey,



Also... Can I create a new attachment (binary file) from within the web service echo method that can be returned to the ppc to create a local updated ppc file.



1. ppc binary file attachment sent to ws echo method...

2. echo method creates local file from attachment...

3. local file gets modified...

4. echo method creates new attachment from modified local file...

5. echo method returns new binary file attachment to ppc

6. ppc creates local modified file...



If I do this all from the same echo method call should I delete the incoming attachment before adding the outgoing attachment?



Also, do you recommend any books that cover web services and DIME?



By the way... This is awesome... 5 Meg transferred in 9 seconds! ;)


Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I get the error "Unable to read data from the transport connection". I tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I also made sure there was plenty of free memory on the ppc device (over 30meg free)



Could this be a web service timeout issue since the larger files inherently take more time or a limitation of another type perhaps with the file system?





//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
C

casey chesnut

//this code worked for me on the server.
//'ba' is from my previous server code, i didnt mess with saving it to disk
MemoryStream buffer = new MemoryStream(ba);
DimeAttachment attachment = new DimeAttachment("image/jpg",TypeFormatEnum.MediaType, buffer);
HttpSoapContext.ResponseContext.Attachments.Add(attachment);
return str;

//and this exposed a bug on my Dime client code
//it was reading the content length as a really large number and running out of memory
//the change needs to be made to DimeRecord.cs, ReadHeader() method

//get content length
//this.m_contentLength = buffer[8] << 24;
//this.m_contentLength = this.m_contentLength + buffer[9] << 16;
//this.m_contentLength = this.m_contentLength + buffer[10] << 8;
//this.m_contentLength = this.m_contentLength + buffer[11];
//this.m_contentLength = (int) BitConverter.ToInt32(buffer, 8);
int n = 0;
for (int i=8;i<11;i++)
n = (n | buffer) << 8;
n = n | buffer[11];
this.m_contentLength = n;

Casey,

That fixed the attachment size problem... thanks...

However when i try returning an attachment the PPC client gives an error. I get an "out of memory" error or "hexadecimal value 0x0C is an invalid character" error.

The echo code is below with notes in the "//CREATE OUTGOING ATTACHMENT" section.

I haven't added code to the client side to read the returned attachment yet. I'm just trying to get the return attachment added to the message.

Any ideas?

Oh.. i got the book. MS .NET XML WS... You're right only 3 pages on DIME :|

[WebMethod]
public string Echo()
{
// Reject any requests which are not valid SOAP requests
if (HttpSoapContext.RequestContext == null)
throw new ApplicationException("Only SOAP requests are permitted.");

//READ INCOMMING ATTACHMENT
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();

//CREATE LOCAL SERVER FILE FROM ATTACHMENT
MemoryStream m = new MemoryStream(ba);
FileStream f = new FileStream( @"c:\temp\temp.jpg", FileMode.Create);
m.WriteTo(f);
m.Close();
f.Close();

////JUST FOR TESTING --- WAIT FOR A FEW SECONDS FOR FILE TO BE COMMITED TO DISK
Thread.Sleep(5000);

//READ FILE INTO A STREAM FOR OUTGOING ATTACHMENT
string myFile = @"c:\temp\temp.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
numRead = fs.Read(bytes, 0, (int)fs.Length);
MemoryStream buffer = new MemoryStream(bytes);

//CREATE OUTGOING ATTACHMENT
// **** the next 2 lines cause an out of memory error
// **** if i remark out the lines the call completes correctly but without the response attachment
DimeAttachment attachment = new DimeAttachment("image/jpg",TypeFormatEnum.MediaType, buffer);
HttpSoapContext.ResponseContext.Attachments.Add(attachment);

fs.Close();
buffer.Close();
return str;
}
the attachment size is likely an ASP.NET configuration,
and usually fails for anything over 4 megs.
see machine.config
<httpRuntime maxRequestLength="4096"

yes, the web service can return an attachment on the same call.
you do not need to delete the incoming attachment, which uses SoapRequest;
because the outgoing attachment will be on the SoapResponse.

there are only a couple books that even mention DIME.
Wiley - Web Service Enhancements
Addison - .NET Web Services
MsPress - Programming .NET Xml Web Services
I think there is an MsPress WSE book coming soon?

Casey,



Also... Can I create a new attachment (binary file) from within the web service echo method that can be returned to the ppc to create a local updated ppc file.



1. ppc binary file attachment sent to ws echo method...

2. echo method creates local file from attachment...

3. local file gets modified...

4. echo method creates new attachment from modified local file...

5. echo method returns new binary file attachment to ppc

6. ppc creates local modified file...



If I do this all from the same echo method call should I delete the incoming attachment before adding the outgoing attachment?



Also, do you recommend any books that cover web services and DIME?



By the way... This is awesome... 5 Meg transferred in 9 seconds! ;)


Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I get the error "Unable to read data from the transport connection". I tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I also made sure there was plenty of free memory on the ppc device (over 30meg free)



Could this be a web service timeout issue since the larger files inherently take more time or a limitation of another type perhaps with the file system?





//for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
string AppPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") + 1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size of the file
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;

the existing DIME sample code calls the WSE 1.0 Echo with no problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost + "/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost + "/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client button click event to send (echo) a binary file that works with the WSE SP1 dime attachment example?
 
K

Kleber

Hi Casey,

I followed the tips in this thread and could do a lot of things with
DIME.
Although I can send and get soap attachments, I can do it only once in
an application.

I put my a 'send/get code' inside a button event and when I click on
it for the very first time, I can send/get soap attachments. However,
when I click on it again, I get an exception saying 'File not found
(404)'.

I don´t get it. I don´t know why, but it cannot reach the web server
for the second time. In the local machine everything runs fine. But
when the web service is on my ISP server, I get this error. I also
tried to make requests using different methods, and it only works for
the very first method call. The other ones cannot reach the server and
the exception is thrown.

Do you have a clue why this happened?

Thanks in advance and thanks for your tool.
Ken.

casey chesnut said:
//this code worked for me on the server.
//'ba' is from my previous server code, i didnt mess with saving it to
disk
MemoryStream buffer = new MemoryStream(ba);
DimeAttachment attachment = new
DimeAttachment("image/jpg",TypeFormatEnum.MediaType, buffer);
HttpSoapContext.ResponseContext.Attachments.Add(attachment);
return str;

//and this exposed a bug on my Dime client code
//it was reading the content length as a really large number and running
out of memory
//the change needs to be made to DimeRecord.cs, ReadHeader() method

//get content length
//this.m contentLength = buffer[8] << 24;
//this.m contentLength = this.m contentLength + buffer[9] << 16;
//this.m contentLength = this.m contentLength + buffer[10] << 8;
//this.m contentLength = this.m contentLength + buffer[11];
//this.m contentLength = (int) BitConverter.ToInt32(buffer, 8);
int n = 0;
for (int i=8;i<11;i++)
n = (n | buffer) << 8;
n = n | buffer[11];
this.m contentLength = n;

Casey,

That fixed the attachment size problem... thanks...

However when i try returning an attachment the PPC client gives an
error. I get an "out of memory" error or "hexadecimal value 0x0C is an
invalid character" error.

The echo code is below with notes in the "//CREATE OUTGOING
ATTACHMENT" section.

I haven't added code to the client side to read the returned
attachment yet. I'm just trying to get the return attachment added to
the message.

Any ideas?

Oh.. i got the book. MS .NET XML WS... You're right only 3 pages on
DIME :|

[WebMethod]
public string Echo()
{
// Reject any requests which are not valid SOAP requests
if (HttpSoapContext.RequestContext == null)
throw new ApplicationException("Only SOAP requests are permitted.");

//READ INCOMMING ATTACHMENT
DimeAttachment da = HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();

//CREATE LOCAL SERVER FILE FROM ATTACHMENT
MemoryStream m = new MemoryStream(ba);
FileStream f = new FileStream( @"c:\temp\temp.jpg",
FileMode.Create);
m.WriteTo(f);
m.Close();
f.Close();

////JUST FOR TESTING --- WAIT FOR A FEW SECONDS FOR FILE TO BE
COMMITED TO DISK
Thread.Sleep(5000);

//READ FILE INTO A STREAM FOR OUTGOING ATTACHMENT
string myFile = @"c:\temp\temp.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
numRead = fs.Read(bytes, 0, (int)fs.Length);
MemoryStream buffer = new MemoryStream(bytes);

//CREATE OUTGOING ATTACHMENT
// **** the next 2 lines cause an out of memory error
// **** if i remark out the lines the call completes correctly but
without the response attachment
DimeAttachment attachment = new
DimeAttachment("image/jpg",TypeFormatEnum.MediaType, buffer);
HttpSoapContext.ResponseContext.Attachments.Add(attachment);

fs.Close();
buffer.Close();
return str;
}
message the attachment size is likely an ASP.NET configuration,
and usually fails for anything over 4 megs.
see machine.config
<httpRuntime maxRequestLength="4096"

yes, the web service can return an attachment on the same call.
you do not need to delete the incoming attachment, which uses
SoapRequest;
because the outgoing attachment will be on the SoapResponse.

there are only a couple books that even mention DIME.
Wiley - Web Service Enhancements
Addison - .NET Web Services
MsPress - Programming .NET Xml Web Services
I think there is an MsPress WSE book coming soon?

Casey,



Also... Can I create a new attachment (binary file) from within
the web service echo method that can be returned to the ppc to create a
local updated ppc file.



1. ppc binary file attachment sent to ws echo method...

2. echo method creates local file from attachment...

3. local file gets modified...

4. echo method creates new attachment from modified local file...

5. echo method returns new binary file attachment to ppc

6. ppc creates local modified file...



If I do this all from the same echo method call should I delete
the incoming attachment before adding the outgoing attachment?



Also, do you recommend any books that cover web services and DIME?



By the way... This is awesome... 5 Meg transferred in 9 seconds!
;)


Thanks Casey.



That worked ;) for files 5 Meg and under.



However I noticed that large files over 5 Meg have a problem. I
get the error "Unable to read data from the transport connection". I
tested it with 4,5,6,7 Meg files. Anything over 5 Meg didn't transfer. I
also made sure there was plenty of free memory on the ppc device (over
30meg free)



Could this be a web service timeout issue since the larger files
inherently take more time or a limitation of another type perhaps with
the file system?





"casey chesnut" <casey@MORE spam PLEASEbrains-N-brawn.com>
wrote in message //for a file, make the client do this:
DimeServ.DimeServWrap dwServ = new DimeServ.DimeServWrap();
//WSE1.0
dwServ.Url = wseHost +
"/WSEQuickstart/Attachments/Attachments.asmx";
//WSE2.0
//dwServ.Url = wseHost +
"/AttachmentsService/Attachments.asmx";
string AppPath =
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
AppPath = AppPath.Substring(0, AppPath.LastIndexOf(@"\") +
1);
string myFile = AppPath + @"HootersCops.jpg";
FileInfo fi = new FileInfo(myFile);
FileStream fs = fi.OpenRead();
byte [] bytes = new byte[fs.Length];
int numRead = fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
MemoryStream buffer = new MemoryStream(bytes);
bNb.Ws.Dime.DimeAttachment attachment = new
bNb.Ws.Dime.DimeAttachment(
"uuid:" + bNb.Sec.Guid.NewGuid().ToString("D"),
"image/jpeg", bNb.Ws.Dime.TypeFormatEnum.MediaType, buffer);
dwServ.RequestAttachments.Add(attachment);
string outStr = dwServ.Echo();
MessageBox.Show(outStr, "success");

//and make the web service do this. it just returns the size
of the file
DimeAttachment da =
HttpSoapContext.RequestContext.Attachments[0];
BinaryReader br = new BinaryReader(da.Stream);
byte [] ba = new byte[br.BaseStream.Length];
int numRead = br.Read(ba, 0, (int)br.BaseStream.Length);
string str = numRead.ToString();
br.Close();
return str;
"casey chesnut" <casey@MORE spam PLEASEbrains-N-brawn.com>
wrote in message
the existing DIME sample code calls the WSE 1.0 Echo with no
problems.
just change the url to point to the correct WS.

//WSE1.0
//dwServ.Url = wseHost +
"/AttachmentsService/Attachments.asmx";
//WSE2.0
dwServ.Url = wseHost +
"/WSEQuickstart/Attachments/Attachments.asmx";


***Casey. Can you provide a simple example of a ppc client
button click event to send (echo) a binary file that works with the WSE
SP1 dime attachment example?


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top