Passing a MailMessage object to a web service

  • Thread starter Thread starter Mark Rae
  • Start date Start date
M

Mark Rae

Hi,

Can anyone please tell me if it's possible to pass a
System.Web.Mail.MailMessage object to a ASP.NET Web Service? Maybe using XML
Serialization / Deserialization? I've been asked to investigate the
possibility of building a front-end web page which captures MailMessage
properties such To, From Subject, Attachments etc, builds a MailMessage
object, passes the MailMessage object to a web service, the web service then
sends the message via the Smtp.Send method.

Any assistance gratefully received.

Best regards,

Mark Rae
 
Mark Rae said:
Hi,

Can anyone please tell me if it's possible to pass a
System.Web.Mail.MailMessage object to a ASP.NET Web Service? Maybe using XML
Serialization / Deserialization? I've been asked to investigate the
possibility of building a front-end web page which captures MailMessage
properties such To, From Subject, Attachments etc, builds a MailMessage
object, passes the MailMessage object to a web service, the web service then
sends the message via the Smtp.Send method.


Hi Mark,

Because the MailMessage type is not Serializable, passing it directly to the
Web Service is difficult. Additionally, once you pass a .NET type to a Web
Service, it is no longer accessible via systems other than .NET, i.e. those
built with Java, Perl, or any other language/platform. If you must pass the
MailMessage, here are a couple ideas:

1. You can use the System.Encoding types to convert the object to a byte
array and pass it across. I believe this would bloat the message being sent
to the Web Service and hurt performance pretty badly. You could turn the
byte array into a Base64 string and pass it as a string parameter, which
would be better because it would eliminate tags around every byte.
2. You can use WSE and add the object to a DIME packet. This would be the
most efficient way to do this.
3. There are probably a few other ways to accomplish this in a creative
manner.

If the ultimate goal is to get the Web Service to send an email, I would
just collect the information that is going to go into the message and send
each piece of information as a parameter to the Web Service. Then I would
have the Web Service instantiate the MailMessage object and then send the
email. This also makes the Web Service interoperate with other platforms,
which is one of the big benefits of Web Services.

Joe
 
Joe,

Thanks very much for your reply.
2. You can use WSE and add the object to a DIME packet. This would be the
most efficient way to do this.

OK - I've done a Google search and haven't come up with much. Can you point
me at a resource somewhere which will get me started?
3. There are probably a few other ways to accomplish this in a creative
manner.

I'm sure! I also fully agree with you that this isn't a particularly
sensible thing to do, but my client is my client and has asked me to
investigate if it can be done and, as I enjoy having my invoices paid, I'm
going to try do it for them... :-)

Mark
 
Mark Rae said:
OK - I've done a Google search and haven't come up with much. Can you point
me at a resource somewhere which will get me started?

I recommend WSE 1.0 w/SP1 because it is a fully supported release:

http://www.microsoft.com/downloads/...94-2635-4d29-a90c-28b282993a41&displaylang=en

There are samples in the docs on how to use DIME. Also, check out the
tracing facilities - they're lifesavers sometimes.

There is a WSE 2.0, but it is an unsupported technology preview and I
wouldn't do much but experiment with it at this time. Also, here is the URL
to the Web Services Center on MSDN. They have a lot of good content:

http://msdn.microsoft.com/webservices/
I'm sure! I also fully agree with you that this isn't a particularly
sensible thing to do, but my client is my client and has asked me to
investigate if it can be done and, as I enjoy having my invoices paid, I'm
going to try do it for them... :-)

Yep, I know all too well. ;)

Joe
 
1. You can use the System.Encoding types to convert the object to a byte
array and pass it across.

Help! I thought this would be a trivial task, but I'm having real difficulty
with it! If I have the following code:

using System.Web.Mail;

MailMessage objMailMessage = new MailMessage();
/*
code here to assign the message properties
*/

how do I then convert the object into a byte array, and then (optionally)
turn it into a Base64 string? Presumably, stitching it back into a
MailMessage object once it's been passed to the web service is simply a
matter of reversing the process...?

Mark
 
Back
Top