none
Attachments AddFileAttachment Timeout EWS Managed API 2.0 Exchange Server 2007 RRS feed

  • Question

  • Hi There,

    I'm trying to send mails with attachments. So I sampled pieces of code and find a solution that works fine for me. Unless the attached file is larger than ca. 100 kb.

    I'm find some issues concerning timeout and buffersize, but nothing seems related to my problem. On the other hand, I can access the same Exchange-Server over OWA. Sending large Attachments there, is no problem.

    Are there any settings in config files or something else, I have to consider?

    Using: Exchange Server 2007 SP3, Framework 4.0, EWS Managed API 2.0

    At this AddFileAttachement-Line, I get a timeout-error:

    message.Attachments.AddFileAttachment("Test.pdf", "c:\\temp\\test.pdf");


    Microsoft.Exchange.WebServices.Data.ServiceRequestException : The request failed. The operation has timed out

    Here is my Code-snippet:

                ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
    
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials("domain\\user", "xyz");
                service.Url = new Uri("https://exchangeServer/EWS/Exchange.asmx");
                //service.Timeout = 300000;
    
                EmailMessage message = new EmailMessage(service);
    
    
                message.ToRecipients.Add("test@domain.com");
                message.Subject = "Subject1";
                //message.SubjectEncoding = System.Text.Encoding.UTF8;
                //message.IsBodyHtml = true;
                message.Body = "test mailbody hello";
                //message.BodyEncoding = System.Text.Encoding.UTF8;
    
                message.Attachments.AddFileAttachment("Test.pdf", "c:\\temp\\test.pdf");
    
                message.SendAndSaveCopy();




    Thanks a lot, Rolf



    • Edited by Rolf Maier Wednesday, April 16, 2014 7:30 PM
    Wednesday, April 16, 2014 7:02 PM

Answers

  • Hi Lee,

    in the meanwhile, we installed the same exchange server 2007 SP3 on a Win 2008 R2 Standard with IIS6. We moved all accounts and everything works fine.

    We not have to change any options in the iis.

    So I close this thread with "a big thanx" to you and marked as solved.

    Thanx a lot, Rolf

    • Marked as answer by Rolf Maier Friday, July 11, 2014 8:11 AM
    Friday, July 11, 2014 8:11 AM

All replies

  • ... we also changed the <maxRequestLength> in web.config of the ews folder. But without sucess.

    	<system.web>
    		<httpRuntime maxRequestLength="671088" />
    		<httpModules>
    			<add name="AuthorizationModule"
    				type="Microsoft.Exchange.Services.AuthorizationModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/>
    			<add name="PerformanceCounterModule"
    				type="Microsoft.Exchange.Services.PerformanceCounterModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/>
    			<add name="LargeRequestModule"
    				type="Microsoft.Exchange.Services.LargeRequestModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/> 
    		</httpModules>
    
    		<webServices>
    			<soapExtensionTypes>
    				<add type="Microsoft.Exchange.Services.ServiceExtensionManager, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" priority="1" group="1"></add>
    				<add type="Microsoft.Exchange.Services.ClientResponseSizeLimitSoapExtension, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" priority="1" group="1"></add>
    			</soapExtensionTypes>
    			<!-- Remove the autogenerated test page and wsdl file generation.  Consumers should use
    			Services.wsdl directly instead of folder.asmx?wsdl (for example) -->
    			<protocols>
    				<remove name="Documentation"/>
    			</protocols>
    		</webServices>
    
    		<identity impersonate="false"/>
    		<!--
                Set compilation debug="true" to insert debugging symbols into the compiled page.
                Because this affects performance, set this value to true only during development.
            -->
    		<compilation debug="false"/>
    		<!--
                The <authentication> section enables configuration of the security authentication
                mode used by ASP.NET to identify an incoming user.
            -->
    		<authentication mode="Windows"/>
    		<!--
                The <customErrors> section enables configuration of what to do if/when an unhandled
                error occurs during the execution of a request.  Specifically, it enables developers
                to configure html error pages to be displayed in place of a error stack trace.
            -->
    		<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
    			<!--
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            -->
    		</customErrors>
    	</system.web>
    </configuration>
    
    
    

    Thursday, April 17, 2014 10:07 AM
  • Just a guess, but you might also try

    <httpRuntime maxRequestLength="671088" executionTimeout="300"/>

    to give it a few minutes to think about it.


    OWA For SmartPhone

    Thursday, April 17, 2014 11:29 AM
  • thanks, I tried out, but no success. The border is at nearly 100 kb. My other testfiles are not much larger, 200 - max 400 kb.
    Thursday, April 17, 2014 1:58 PM
  • any ideas?
    Friday, April 25, 2014 12:55 PM
  • Not really. But why did you comment out

    //service.Timeout = 300000;

    in your code? Uncommenting that, in combination with your web.config changes, might help.


    OWA For SmartPhone

    Friday, April 25, 2014 7:32 PM
  • service.Timeout controls your timeout for sending and receiving http web responses. I agree with Lee that you should uncomment this along with the change you made in the web.config may solve your issue.

    Let us know how it goes.

    Saturday, April 26, 2014 4:27 AM
  • I tried out that changes, restarted the server, but it tooks no effect. I changed both parts: web.config and the timeout in my code. But I don't think, that it is really a time-problem.

    In my opinion the features should work together? EWS API 2.0, Exchange Server 2007 SP3 and .Net FW 4.0. Is that right?

    Are there any generally options, I should check out. But with OWA the same Attachments (PDF) works fine.

    This is the actual system.web node of the web.config in the ews folder

    	<system.web>
    		<httpRuntime maxRequestLength="30000" executionTimeout="300"/>
    		<httpModules>
    			<add name="AuthorizationModule"
    				type="Microsoft.Exchange.Services.AuthorizationModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/>
    			<add name="PerformanceCounterModule"
    				type="Microsoft.Exchange.Services.PerformanceCounterModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/>
    			<add name="LargeRequestModule"
    				type="Microsoft.Exchange.Services.LargeRequestModule, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35"/> 
    		</httpModules>
    
    		<webServices>
    			<soapExtensionTypes>
    				<add type="Microsoft.Exchange.Services.ServiceExtensionManager, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" priority="1" group="1"></add>
    				<add type="Microsoft.Exchange.Services.ClientResponseSizeLimitSoapExtension, Microsoft.Exchange.Services, Version=8.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35" priority="1" group="1"></add>
    			</soapExtensionTypes>
    			<!-- Remove the autogenerated test page and wsdl file generation.  Consumers should use
    			Services.wsdl directly instead of folder.asmx?wsdl (for example) -->
    			<protocols>
    				<remove name="Documentation"/>
    			</protocols>
    		</webServices>
    
    		<identity impersonate="false"/>
    		<!--
                Set compilation debug="true" to insert debugging symbols into the compiled page.
                Because this affects performance, set this value to true only during development.
            -->
    		<compilation debug="false"/>
    		<!--
                The <authentication> section enables configuration of the security authentication
                mode used by ASP.NET to identify an incoming user.
            -->
    		<authentication mode="Windows"/>
    		<!--
                The <customErrors> section enables configuration of what to do if/when an unhandled
                error occurs during the execution of a request.  Specifically, it enables developers
                to configure html error pages to be displayed in place of a error stack trace.
            -->
    		<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
    			<!--
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            -->
    		</customErrors>
    	</system.web>
    

    Monday, April 28, 2014 6:41 PM
  • Can you find the IIS log entries generated by the attempt to POST the attachment?

    OWA For SmartPhone

    Tuesday, April 29, 2014 10:00 AM
  • I believe, the logging isn't enabled. Is it the logging-feature, that I can find in the iis-manager at the properties of the websites node? If so, I will post it in the evening.

    The only thing i can find is an entry in the httperr.log: (xx.xx.xx.xx was our fixed ip address)

    #Software: Microsoft HTTP API 1.0
    #Version: 1.0
    #Date: 2014-04-28 17:23:31
    #Fields: date time c-ip c-port s-ip s-port cs-version cs-method cs-uri sc-status s-siteid s-reason s-queuename
    2014-04-28 17:23:31 xx.xx.xx.xx 6948 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-28 17:29:16 xx.xx.xx.xx 56246 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-28 18:07:51 192.168.0.177 52992 192.168.0.222 443 HTTP/1.1 POST /EWS/Exchange.asmx - 1 Timer_ConnectionIdle MSExchangeServicesAppPool
    2014-04-28 20:24:13 xx.xx.xx.xx 1145 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-28 20:41:22 xx.xx.xx.xx 46682 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-28 20:42:12 xx.xx.xx.xx 61928 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 07:31:56 xx.xx.xx.xx 54498 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 07:32:01 xx.xx.xx.xx 58369 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 08:40:55 xx.xx.xx.xx 62600 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 09:35:04 192.168.0.177 60707 192.168.0.222 443 HTTP/1.1 POST /EWS/Exchange.asmx - 1 Timer_ConnectionIdle MSExchangeServicesAppPool
    2014-04-29 10:06:19 xx.xx.xx.xx 2787 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 10:27:53 xx.xx.xx.xx 46495 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 10:45:23 xx.xx.xx.xx 15608 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 11:00:08 xx.xx.xx.xx 43805 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 11:29:22 xx.xx.xx.xx 20710 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 11:43:02 xx.xx.xx.xx 12101 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 11:43:17 xx.xx.xx.xx 23003 192.168.0.222 777 - - - - - Timer_ConnectionIdle -
    2014-04-29 12:05:07 192.168.0.177 62111 192.168.0.222 443 HTTP/1.1 POST /EWS/Exchange.asmx - 1 Timer_ConnectionIdle MSExchangeServicesAppPool
    

    Tuesday, April 29, 2014 12:42 PM
  • The Timer_ConnectionIdle looked promising, but a search seems to indicate that it's not important:

    http://blogs.msdn.com/b/webtransports/archive/2004/07/15/184336.aspx

    But yes, it is the logging feature you found in IIS Manager. Normally, it is enabled, but if you don't routinely look at these things, you can save disk space by turning it off.


    OWA For SmartPhone

    Tuesday, April 29, 2014 12:58 PM
  • This is the IIS Log. The first six rows are the successful attempt with a small attachment. The las two rows ist the failed attempt.

    #Software: Microsoft Internet Information Services 6.0
    #Version: 1.0
    #Date: 2014-04-29 15:45:43
    #Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status 
    2014-04-29 15:47:50 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx SoapAction=CreateItem;Version=1;RpcC=9;RpcL=109;LdapC=9;LdapL=16; 443 DOMAIN\USER 192.168.0.177 ExchangeServicesClient/15.00.0847.030 200 0 0
    2014-04-29 15:47:50 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx - 443 - 192.168.0.177 ExchangeServicesClient/15.00.0847.030 401 2 2148074254
    2014-04-29 15:47:50 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx SoapAction=CreateAttachment;Version=1;RpcC=15;RpcL=93;LdapC=0;LdapL=0; 443 DOMAIN\USER 192.168.0.177 ExchangeServicesClient/15.00.0847.030 200 0 0
    2014-04-29 15:47:50 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx - 443 - 192.168.0.177 ExchangeServicesClient/15.00.0847.030 401 2 2148074254
    2014-04-29 15:47:50 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx SoapAction=SendItem;Version=1;RpcC=6;RpcL=15;LdapC=0;LdapL=0; 443 DOMAIN\USER 192.168.0.177 ExchangeServicesClient/15.00.0847.030 200 0 0
    2014-04-29 15:48:15 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx - 443 - 192.168.0.177 ExchangeServicesClient/15.00.0847.030 401 2 2148074254
    2014-04-29 15:48:15 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx SoapAction=CreateItem;Version=1;RpcC=6;RpcL=15;LdapC=1;LdapL=0; 443 DOMAIN\USER 192.168.0.177 ExchangeServicesClient/15.00.0847.030 200 0 0
    2014-04-29 15:48:15 W3SVC1 192.168.0.222 POST /EWS/Exchange.asmx - 443 - 192.168.0.177 ExchangeServicesClient/15.00.0847.030 401 2 2148074254

    Tuesday, April 29, 2014 4:06 PM
  • It's a shame that the failed CreateAttachment isn't even logged here. Do you see a corresponding entry in the httperr.log file at 2014-04-29 15:48:15 ?

    OWA For SmartPhone

    Wednesday, April 30, 2014 10:57 AM
  • Yes, a little bit later. I believe it is after the timeout-error.

    #Software: Microsoft HTTP API 1.0
    #Version: 1.0
    #Date: 2014-04-29 15:50:26
    #Fields: date time c-ip c-port s-ip s-port cs-version cs-method cs-uri sc-status s-siteid s-reason s-queuename
    2014-04-29 15:50:26 192.168.0.177 64240 192.168.0.222 443 HTTP/1.1 POST /EWS/Exchange.asmx - 1 Timer_ConnectionIdle MSExchangeServicesAppPool
    

    I still believe it's not really a timeout problem. A file with a 80 kb needs only a second. A file with 150 kb should init a timeout ... ? Are there any generally options I can check?

    Wednesday, April 30, 2014 11:15 AM
  • That just looks like IIS closing the connection. And I'm afraid that I can't think of any configuration options for this, especially since we're not even talking about a particularly large file.

    I expect the meaning of the word 'timeout' is going to be significant. Normally, you'd think it means that the transmission of a large file is taking too long. But in this case, I think it means it has given up waiting for any response at all.

    Did you try turning on EWS request and response tracing?


    OWA For SmartPhone

    Wednesday, April 30, 2014 11:38 AM
  • Ok, I will implement a TraceListener, and post the results shortly. In the meantime, first I would like to thank for your support.
    Wednesday, April 30, 2014 12:01 PM
  • No problem. I just wish I had a better idea of what was going wrong.

    OWA For SmartPhone

    Wednesday, April 30, 2014 12:12 PM
  • Now, I implemented the TraceListener. If I understand it correctly. The request and the response is ok, but the connection closes unexspectedly.

    This is the request:

    <Trace Tag="EwsRequest" Tid="1" Time="2014-05-03 21:11:16Z" Version="15.00.0847.030">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2007_SP1" />
          <t:TimeZoneContext>
            <t:TimeZoneDefinition Id="W. Europe Standard Time" />
          </t:TimeZoneContext>
        </soap:Header>
        <soap:Body>
          <m:CreateAttachment>
            <m:ParentItemId Id="AAMkADQ1YmVmMmM1LTZjMDEtNDk3Yy05Mjc3LTdlNzdkMzBkOTQ0NABGAAAAAAADbsD3gWI5RKvmttUxJQW/BwDOy8/p5VaGTq1B1FJD/FzsAKIDOssOAADOy8/p5VaGTq1B1FJD/FzsAKIgiej3AAA=" />
            <m:Attachments>
              <t:FileAttachment>
                <t:Name>TestPdf2.pdf</t:Name>
                <t:Content>JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvU< shorten the content >GFnZXMgMiAwIFIvTGFuZyhkZS1ERSkgL1N0cnN0bSAxOTI1NjY+Pg0Kc3RhcnR4cmVmDQoxOTQ0ODgNCiUlRU9G</t:Content>
              </t:FileAttachment>
            </m:Attachments>
          </m:CreateAttachment>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    
    and this the response:

    <Trace Tag="EwsResponse" Tid="1" Time="2014-05-03 21:11:16Z" Version="15.00.0847.030">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Header>
          <t:ServerVersionInfo MajorVersion="8" MinorVersion="3" MajorBuildNumber="342" MinorBuildNumber="0" Version="Exchange2007_SP1" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
        </soap:Header>
        <soap:Body>
          <m:CreateItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
            <m:ResponseMessages>
              <m:CreateItemResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Items>
                  <t:Message>
                    <t:ItemId Id="AAMkADQ1YmVmMmM1LTZjMDEtNDk3Yy05Mjc3LTdlNzdkMzBkOTQ0NABGAAAAAAADbsD3gWI5RKvmttUxJQW/BwDOy8/p5VaGTq1B1FJD/FzsAKIDOssOAADOy8/p5VaGTq1B1FJD/FzsAKIgiej3AAA=" ChangeKey="CQAAABYAAADOy8/p5VaGTq1B1FJD/FzsAKIgigmS" />
                  </t:Message>
                </m:Items>
              </m:CreateItemResponseMessage>
            </m:ResponseMessages>
          </m:CreateItemResponse>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    

    Saturday, May 3, 2014 9:28 PM
  • Now we have a new approach. Until now we tested the System on a Exchange Server 2007 SP3 hosted on a MS Server 2003 R2 with IIS 6.

    The current Test runs also on a Exchange Server 2007 SP3 but hosted on MS Server 2008 R2 with IIS 7.5. And it works very fine, using the standard web.config in the EWS-Folder.

    Are there any settings to persuade the IIS 6 on 2003 R2?

    Monday, May 5, 2014 2:34 PM
  • It looks like you already had it covered with maxRequestLength

    http://weblogs.asp.net/jeffwids/archive/2009/09/24/from-iis6-maxrequestlength-to-iis7-maxallowedcontentlengthfile-specifying-maximum-file-upload-size.aspx

    But strangely, your trace is returning a success code. Does the attachment actually get attached to the Draft message before the timeout occurs? Or is there no attachment?


    OWA For SmartPhone

    Monday, May 5, 2014 4:16 PM
  • We changed the maxRequestLength in the web.config in the EWS Folder. The problem only occurs in the IIS6 enviroment. Are there any correspondig web.config-Files concerned ... like in the Autodiscover, OWA, Sync - Folder / .Net Folders or something else ...?

    The attachment didn't get attached to the draft massage. The other items in the mail are completely successful ... To, Subject, Body ...

    Tuesday, May 6, 2014 3:32 PM
  • Since the data gets posted to a resource within the EWS VDir, the web.config in the EWS vdir takes precedence over any others that will be on the server.

    You might try removing and recreating the EWS VDir.

    I no longer have IIS 6 anywhere, so I can't dig around for any settings in the IIS Manager GUI. I assume you've examined all the properties of the Server, Site, and EWS application in IIS Manager? If there's a metabase setting somewhere for this, I don't know how the priorities will work out.

    Do you have any other IIS6 CAS's to try it out on?


    OWA For SmartPhone

    Wednesday, May 7, 2014 9:51 AM
  • Hi Lee,

    in the meanwhile, we installed the same exchange server 2007 SP3 on a Win 2008 R2 Standard with IIS6. We moved all accounts and everything works fine.

    We not have to change any options in the iis.

    So I close this thread with "a big thanx" to you and marked as solved.

    Thanx a lot, Rolf

    • Marked as answer by Rolf Maier Friday, July 11, 2014 8:11 AM
    Friday, July 11, 2014 8:11 AM