Click here to Skip to main content
12,699,367 members (34,435 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WCF C#4.0
Getting error described in the Subject, it only happens when a very large attachment is being sent by the Test Console app to the Email service, even though the attachment is within the permitted size, I am guessing I have a problem with such very large attachment at the Test Console app because I get the error from the Test Console app (before it hits the service), otherwise I have something wrong in my configuration, please help.

// Here is the Test Console application that is designed to send an email with very large attachment to the Email Service:

                EmailSerClient proxy = new EmailSerClient();
                EmailMessage emailMsg = new EmailMessage();
                emailMsg.EmailParamHeaders = new DataContracts.Email();

                emailMsg.EmailParamHeaders.To = new string[2];
                emailMsg.EmailParamHeaders.CC = new string[1];

                emailMsg.EmailParamHeaders.From = "";
                emailMsg.EmailParamHeaders.To[0] = "";

                emailMsg.EmailParamHeaders.Subject = "Test line here";
                emailMsg.EmailParamHeaders.Message = "test message here.";
                emailMsg.EmailParamHeaders.AttachmentFileName = @"c:\log\";  //null; 

                string filePath = System.IO.Path.Combine(@"c:\log\", "");
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

               //  open stream
                System.IO.FileStream stream = new System.IO.FileStream(@"c:\log\",
                System.IO.FileMode.Open, System.IO.FileAccess.Read);

               // See RemoteFileInfo class below:
                RemoteFileInfo result = new RemoteFileInfo();

                // return result 
                result.FileName = "";
                result.Length = fileInfo.Length;
                result.FileByteStream = stream;

                    proxy.SendEmail(emailMsg.EmailParamHeaders, result.FileByteStream);//Stream.Null);

                catch (Exception e)

// Here is the RemoteFileInfo class which I think might be part of the problem:

using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.ServiceModel.Web;
using System.ServiceModel;

namespace wcfTestConsoleApp
    public class RemoteFileInfo : IDisposable
        [MessageHeader(MustUnderstand = true)]
        public string FileName;

        [MessageHeader(MustUnderstand = true)]
        public long Length;

        [MessageBodyMember(Order = 1)]
        public System.IO.Stream FileByteStream;

        public void Dispose()
            if (FileByteStream != null)
                FileByteStream = null;

// Here is the config file for the Test Client above:

                <binding name="BasicHttpBinding_IEmailService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000" />

                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                        <message algorithmSuite="Default" />
Posted 6-Sep-12 7:31am
Updated 6-Sep-12 7:40am
Martin Arapovic 6-Sep-12 15:46pm
Problem can occur because of many things.
I suggest you to turn on trace for your wcf srevice and then using Service trace Viewer tool to check if there is any exception inside WCF infrastructure. It's easy and all things are done in service web.config file. How to turn WCF tracing search on google. Use Service Trace Viewer Tool to analyze trace.
One more thing. I see you are trying to send some file, so try to change transferMode="StreamedResponse" within your binding configuration and make sure that your service and client have the same configuration (bindings and so on).
Important note: As I remember, WCF streaming was not supported by the ASP.NET Development Server, so make sure that you deploy your service to IIS or host it inside your test app, before making any tests.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Firstly I would setup tracing on your wcf service:[^]

Once this is in place you can see the logs generated and you get a better idea of the actual problem.

It would also be worth adding the following:

1) setting the max object graph in the endpoint behavior and service behavior

        <behavior name="EmailWCFServiceTypeBehaviors">
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
          <servicemetadata httpgetenabled="True" />
          <servicedebug includeexceptiondetailinfaults="True" />
        <behavior name="endpointBehavior">
          <datacontractserializer maxitemsinobjectgraph="2147483647" />

2) set the endpoint and service to use the behaviors.

3) optionally increase the http request timeout.

                <httpruntime executiontimeout="180" />
Member 8714829 7-Sep-12 12:39pm
Thank you for the suggestion, I have tried the updates on the service itselfm time I get the following error:

The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
<title>Runtime Error</title>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

<body bgcolor="white">


Server Error in '/EmailWcfService' Application.

Runtime Error

Member 8714829 7-Sep-12 13:05pm
Given the detailed message above, I noticed this error in the InnerException msg:
{"The remote server returned an error: (500) Internal Server Error."}
Member 8714829 7-Sep-12 19:30pm
Found the cause of the problem and now looking for a solution (see error msg below), this was possible after some tracing):

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Not sure why the web.config MaxReceivedMessageSize is being overridden with this value... any ideas on how to force the web.config value to take affect?
db7uk 9-Sep-12 18:33pm
Sorry for the late reply. The reader quota will be on the client connection. I notice your are calling proxy.SendMail. How is the service being instanciated? Can I recommend you create the proxy in code. You can set the readaquotas programmatically. One other thing, dont wrap the proxy in a using statement. try or for good ways to call wcf services.
Member 8714829 10-Sep-12 15:23pm
The service is being instanciated by including the generated class from the original wcf service using svcutil.exe. What I do after creating the proxy class is that I add the existing item into the test console app/client...
On a second note I did take the proxy.SendMail outside the try-catch structure, so far I am still having the same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100