Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

DXRichEdit for Silverlight: Building a mail application with the RichEditControl

$
0
0

This example illustrates how the built-in document export functionality in the RichEditControl can be used to construct a simple application that will allow you to send a document via email. A document loaded into the RichEditControl is sent in the HTML email format. Note that images in this format should be defined according to the RFC 2392 (Content-ID and Message-ID Uniform Resource Locators) specification. To achieve this in the context of the RichEditControl HTML export functionality, override the IUriProvider Interface as shown in the counterpart code example for the WPF platform (DXRichEdit for WPF: Building a mail application with the RichEditControl). However, in a Silverlight environment we cannot send an email message directly because the System.Net.Mail functionality is not available in the Silverlight framework. To workaround this limitation, you can create a Silverlight-enabled WCF Service and pass the necessary email message data to it in order to construct, and send a MailMessage (System.Net.Mail) in the context of this service. This technique is described in the How to send an email in Silverlight Part 1 webpage. In our scenario we define service and data contracts as follows:

[C#]
[ServiceContract]publicinterfaceIMailService{[OperationContract]voidSendMail(stringmailHost,stringfrom,stringto,stringsubject,stringbody,List<AttachementInfo>attachments);}[DataContract]publicclassAttachementInfo{[DataMember]publicbyte[]Data{get;set;}[DataMember]publicstringMimeType{get;set;}[DataMember]publicstringContentId{get;set;}}

Note that when the AttachementInfo.Data array contains a large amount of data, a WCF service might fail to accept it. For this reason, we defined service binding as follows in the server-side Web.config file:

[XML]
...<basicHttpBinding><!-- The maxReceivedMessageSize attribute is added to allow the posting of a large amount of data to the service --><bindingname="largeBuffer"maxBufferSize="2147483647"maxReceivedMessageSize="2147483647"><readerQuotasmaxStringContentLength="2147483647"/></binding></basicHttpBinding> ...

Sometimes, service client proxy generation or its update might fail due to some unusual Visual Studio behavior. To fix this issue and correctly generate/update client proxy, use the recommendation from the Silverlight: Update service reference for a WCF service generating empty class webpage.

Here is a screenshot that illustrates a sample application in action:

Additional information:

1) Note the way we handle service faults in order to display an error in a Silverlight client. We have registered an alternative client HTTP stack (see Creating and Handling Faults in Silverlight) and handled the MailServiceClient.SendMailCompleted event in our code to intercept error information. It might be useful because sometimes the mail server might be unavailable, and this situation will be reported to the client when this fault handling technique is used. In addition, we have enabled service logging as follows:

[XML]
...<system.diagnostics><sources><sourcename="System.ServiceModel"switchValue="Information, ActivityTracing"propagateActivity="true"><listeners><addname="traceListener"type="System.Diagnostics.XmlWriterTraceListener"initializeData="C:\RichEditSendMailSL.svclog"/></listeners></source></sources></system.diagnostics> ...

2) Since the Silverlight client application should be hosted in the context of a website application, make sure that the former is defined as a startup project in Visual Studio. In addition, since the WCF service is referenced by the client via an address with a static port (see the ServiceReferences.ClientConfig file), disable the "Use dynamic ports" option:


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>