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?