I am inheriting and modifying the System.Net.MailMessage class for use in a web service. I need to keep it named MailMessage for other reasons. When I use this in the code below, I get the error below.
“Types ‘System.Net.Mail.MailMessage’ and ‘TestWebService.MailMessage’ both use the XML type name, ‘MailMessage’, from namespace ‘http://tempuri.org/’. Use XML attributes to specify a unique XML name and/or namespace for the type.”
I belive I have to add XMLRoot and Type attributes, but I can’t seem to figure out the right combination. What do I need to do to resolve this error?
namespace TestWebService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string Test(MailMessage emailMessage)
{
return "It Worked!";
}
}
}
namespace TestWebService
{
public class MailMessage : System.Net.Mail.MailMessage
{
public MailMessage() : base()
{
}
}
}
You have to add
XmlTypeAttributeto change the name or namespace to make it unique for serializationHowever,
System.Net.Mail.MailMessageitself is not serializable so your class that is derived from it won’t be serializable.