WCF + SmtpClient: only works in a Windows 2008 environment
Continuing the discussion started in another post: I used windows service to host a WCF mail sender. The service itself is quite simple: it uses a DataContract to get the basic System.Net.Mail.MailMessage
class properties (supports attachment - please see the mentioned post, code by edosoft) and the System.Net.Mail.SmtpClient
class to actually send the e-mail. The .NET framework used was 3.5SP1 (with VS2008).
Please note that I already had the code working inside an assembly; the exercise was just to e开发者_JAVA百科xpose the functionality by using a WCF service. I used basicHttpBinding
for the endpoint binding, no additional configurations.
When I tested the service in my desktop environment (Windows XP) I noticed the following:
The e-mails were only sent if I restarted the windows service in the first 10-15 seconds after calling the WCF service, otherwise nothing would happen;
No exception/error messages whatsoever in the service trace/log files;
No exception/error messages when calling the
SmtpClient.Send(MailMessage msg)
method or anywhere else when running the service code.
I played with different bindings and configurations for a while, even tried to send the message from a different thread - no changes. I actually came accross with a forum question related to this problem: the same method called from within an ASMX webservice would only work is an IISRESET was performed. I was able to replicate this issue by creating an ASMX webservice using the same sending code used in the WCF. Hosting the WCF service under IIS was also of no help (same problem).
I decided then to deploy the service in a Windows 2008 environment (windows service hosted) - see, no changes in the original, simple code. Same configuration, same everything. It worked right away, no delays or any other problem I could identify. Does anyone have any idea about this issue? I'll try it in a Windows 2003 environment now, but I'd like to know if it's actually a known bug/limitation, or if it's somehow related to the ASMX bug related (as it appears to be). Does anyone have seen it before?
Thanks,
精彩评论