.Net ramblings
# Thursday, 24 June 2004
Http Status 400 trying to send large DIME attachments

Testing out my new DIME attachment code with WSE2, i ran into http errors with large uploads.  The error i got was a System.Net.WebException saying that it was a bad request, Http status 400, with an event in the application log under WSE:

HTTP/ASMX Message Receive Failure: Microsoft.Web.Services2.Dime.DimeFormatException: WSE352: The size of the record uuid:c0c3c949-5fb1-4171-88aa-06ce14499e44 exceed its limit.
at Microsoft.Web.Services2.Dime.DimeRecord.UpdateTotalBytesRead...

I had the maxRequestLength set to 128000 in web.config, but i found out that this does not apply to WSE2.  adding the following entry into web.config solved the problem.

<?xml version="1.0" encoding="utf-8" ?>
 <configuration>
  <microsoft.web.services2>
   <messaging>
    <maxRequestLength>256000</maxRequestLength><!-- 256 mb -->
   </messaging>
 </microsoft.web.services2>
...

Thursday, 24 June 2004 09:49:24 (GMT Daylight Time, UTC+01:00)  #    Comments [8]  Asp.Net

Wednesday, 21 July 2004 13:06:23 (GMT Daylight Time, UTC+01:00)
I have the same problem with you,and I have added the "masRequestLength" block to the web.config,but it still doesn't work.
The length of my attachment is about 10M, and I used the method which MSDN told me (the "WriteToDime" method and the "ReadFromDime" method) but it still couldn't solve the problem.
I hope someone could help me.
The two methods talked above is on http://www.microsoft.com/china/msdn/archives/library/dnwebsrv/html/wsedime.asp
Sorry for Chinese web page,but I think it doesn't matter.

Thank you.
Liu Xuhui
Wednesday, 21 July 2004 13:22:01 (GMT Daylight Time, UTC+01:00)
hi liu,
try setting the httpRunTime maxRequestLength as well as the WSE2 setting.

...
<system.web>
<httpRuntime executionTimeout="300" maxRequestLength="256000" />
...

if this doesn't do it, i would suggest posting your question on microsoft.public.dotnet.framework.webservices.enhancements.

i have had all my questions answered very well there.
best of luck
tim
tim mackey
Tuesday, 17 May 2005 22:32:25 (GMT Daylight Time, UTC+01:00)
Thanks Tim! You saved my butt! Had to have this problem fixed asap and it took a long time to find the answer - thank you so much for blogging this.
Mike
Tuesday, 02 August 2005 17:43:25 (GMT Daylight Time, UTC+01:00)
Can you send me a snippet (or post it) of how to actually call WriteToDime and ReadFromDime? I've been banging my head against the wall trying to figure it out?

Do you call WriteToDime before or after you make your web service call? What streams do you pass it? I'm really dying here :(
David Talbot
Tuesday, 02 August 2005 21:29:15 (GMT Daylight Time, UTC+01:00)
Sure, no problem.

Here is the code in my winforms app that sends a file to the server:

using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Dime;
...
DimeAttachment dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, f.FullName); // 'f' is a FileInfo object
this.WebService.RequestSoapContext.Attachments.Add(dimeAttach); // my web service proxy object is called ‘WebService’
this.WebService.uploadFile(f.Name); // this method actually invokes the web method, and the attachment just goes along with it.



then.. on the web service side of things:

/// <summary>
/// This method requires one dime attachment to be added to the message,
/// </summary>
[WebMethod]
public void upload(string filename)
{
if(RequestSoapContext.Current.Attachments.Count == 0)
throw new ApplicationException("No attachments were sent with the message.");

if(filename == null)
throw new Exception("No filename passed to upload method on server");

try
{
string path = Server.MapPath("Upload"); // the web identity account should have write permissions on this directory
if(!Directory.Exists(tmpPath))
Directory.CreateDirectory(tmpPath);

this.WriteStreamToDisk(RequestSoapContext.Current.Attachments[0].Stream, path + "\\" + filename);
}
catch(Exception ex)
{
throw ex;
}
}

// A handy method to write a stream to a disk
private void WriteStreamToDisk(Stream stream, string absolutePath)
{
try
{
FileStream f = System.IO.File.OpenWrite(absolutePath);
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Close();
f.Write(bytes, 0, bytes.Length);
f.Close();
}
catch(Exception ex)
{
throw ex; // or log it...
}
}

Hope this sets you straight!
Tim
Tim Mackey
Wednesday, 14 February 2007 07:33:03 (GMT Standard Time, UTC+00:00)
hi! is it possible for client such as php and java apps to consume the attachment(for download)? what adjustments do they need to make for them to do so. by the way, this is a great article, thanks man!
george
Wednesday, 14 February 2007 08:51:55 (GMT Standard Time, UTC+00:00)
hi george. xml web services are an open standard, and there is no reason why any other platform shouldn't be able to interoperate. having said that, web services weren't invented when i last used java or php so i can't help you there! i did find a link though that may be of some use: http://www.javaworld.com/javaworld/jw-09-2003/jw-0912-fop.html
good luck
tim
tim
Saturday, 14 January 2012 19:47:01 (GMT Standard Time, UTC+00:00)
WorldxGaming


WorldxGaming :: Instant Level 80.
:: PvP and Arena Ranks.
:: Vote and be Rewarded.
:: Gold for Free.
:: 3x Honor , 4x reputation , 2x Arena.
:: +71 Talents
:: Scripted Instances
:: Custom armor and unique weapon
:: Active PvP System
:: Random Battleground
:: No Lag , No Disconnect
:: Custom Quests
:: Full Scripted Instances
:: Friendly Gms

http://www.worldxgaming.com/
Eevo
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview