I have had a big problem on transmitting attachments with DIME.
I want to transmit big attachments as large as 10M ,so I split the file into several blocks and treat each of them as one attachment.But after I receive the attachment,it doesn't work well.
The source code of the webmethod are here:
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
FileStream fs = new FileStream(@"C:\10M_Attachment_Test.DAT", FileMode.Open);
WriteToDime1(fs, "dat", respContext);
}
private void WriteToDime1(Stream inputStr, string mediaType,SoapContext respContext)
{
byte[] bytes = new byte[fsize];
int numBytes;
DimeAttachment dimeAttach;
int num = 0;
while((numBytes = inputStr.Read(bytes, 0, size)) > 0)
{
MemoryStream dimeStr = new MemoryStream();
DimeWriter myDW = new DimeWriter(dimeStr);
DimeRecord myRecord = myDW.LastRecord(num.ToString(), mediaType,
TypeFormat.MediaType, -1);
num++;
myRecord.ChunkSize = fsize;
BinaryWriter myWriter = new BinaryWriter(myRecord.BodyStream);
myWriter.Write(bytes, 0, numBytes);
dimeAttach = new DimeAttachment("dat", TypeFormat.MediaType, dimeStr);
dimeAttach.ChunkSize = Int32.MaxValue;
respContext.Attachments.Add(dimeAttach);
}
}
The source code of the Client are here:
if (svc.ResponseSoapContext.Attachments.Count >0)
{
FileStream fs = new FileStream(@"C:\cuiheming.rar", FileMode.OpenOrCreate); int numBytes = 0;
int size = 4096;
int fsize = 4*4096;
byte[] bytes = new byte[size];
try
{
foreach(Attachment at in svc.ResponseSoapContext.Attachments)
{
DimeReader myDR = new DimeReader(at.Stream);
DimeRecord myRecord = myDR.ReadRecord(); (***)
myRecord.ChunkSize = fsize;
BinaryReader myReader = new BinaryReader(myRecord.BodyStream);
if((numBytes = at.Stream.Read(bytes, 0, size)) > 0)
{
fs.Write(bytes, 0, numBytes);
}
}
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
The line marked with *** throws exception saying that "Can not read from the stream",and I found that the length of at.Stream is 0!
Can anyone help me to solve the problem?
Thank you!
--
FROM 202.205.168.*