Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 = "noreply@xys.com";
                emailMsg.EmailParamHeaders.To[0] = "abc@xys.com";
 
                emailMsg.EmailParamHeaders.Subject = "Test line here";
                emailMsg.EmailParamHeaders.Message = "test message here.";
                emailMsg.EmailParamHeaders.AttachmentFileName = @"c:\log\attchment.zip";  //null; 

                string filePath = System.IO.Path.Combine(@"c:\log\", "attachment.zip");
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
 
               //  open stream
                System.IO.FileStream stream = new System.IO.FileStream(@"c:\log\attachment.zip",
                System.IO.FileMode.Open, System.IO.FileAccess.Read);
 
               // See RemoteFileInfo class below:
                RemoteFileInfo result = new RemoteFileInfo();
 
                // return result 
                result.FileName = "attachment.zip";
                result.Length = fileInfo.Length;
                result.FileByteStream = stream;
 
                try
                {
                    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
{
    [MessageContract]
    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.Close();
                FileByteStream = null;
            }
        }
    }
}
 
// Here is the config file for the Test Client above:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <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" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/EmailWcfService/EmailService.svc"
                binding="basicHttpBinding" bindingConfiguration=""
                contract="IEmailService" name="BasicHttpBinding_IEmailService">
                <identity>
                    <servicePrincipalName value="host/abcdefg.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
 
// Here below is the Email service's config file in relation to serviceModel/binding...etc.:
 
<pre lang="xml"><system.serviceModel>
      <behaviors>
          <serviceBehaviors>
              <behavior name="EmailWCFServiceTypeBehaviors">
                  <serviceMetadata httpGetEnabled="true"/>
                 
                  <serviceDebug includeExceptionDetailInFaults="true"/>
              </behavior>
          </serviceBehaviors>
      </behaviors>
      <bindings>
          <basicHttpBinding>
              <binding name="httpLargeMessageStream"         transferMode="StreamedRequest" maxReceivedMessageSize="52428800" maxBufferSize="52428800"/>
          </basicHttpBinding>
      </bindings>
      <services>
    <service name="EmailService" behaviorConfiguration="EmailWCFServiceTypeBehaviors">
              
      <endpoint address="" binding="basicHttpBinding" contract="IEmailService"  bindingNamespace=""/>
 
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
 
<system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
     <directoryBrowse enabled="true"/>
</system.webServer
Posted 6-Sep-12 6:31am
Edited 6-Sep-12 6:40am
v2
Comments
Martin Arapovic at 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
good
Please Sign up or sign in to vote.

Solution 1

Firstly I would setup tracing on your wcf service:
 
http://msdn.microsoft.com/en-us/library/ms733025.aspx[^]
 
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
 
<servicebehaviors>
        <behavior name="EmailWCFServiceTypeBehaviors">
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
          <servicemetadata httpgetenabled="True" />
          <servicedebug includeexceptiondetailinfaults="True" />
        </behavior>
      </servicebehaviors>
      <endpointbehaviors>
        <behavior name="endpointBehavior">
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
        </behavior>
      </endpointbehaviors>
 
2) set the endpoint and service to use the behaviors.
 
3) optionally increase the http request timeout.
 
<system.web>
                <httpruntime executiontimeout="180" />
        </system.web>
  Permalink  
Comments
Member 8714829 at 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>
<head>
<title>Runtime Error</title>
<style>
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; }
</style>
</head>
 
<body bgcolor="white">
 
<span>

Server Error in '/EmailWcfService' Application.

 

Runtime Error

<'.>
Member 8714829 at 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 at 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 at 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 http://www.codeproject.com/Tips/197531/Do-not-use-using-for-WCF-Clients or http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx for good ways to call wcf services.
Member 8714829 at 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
0 Sergey Alexandrovich Kryukov 269
1 Peter Leow 205
2 OriginalGriff 200
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2014
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