Link to home
Start Free TrialLog in
Avatar of programmerist 1983
programmerist 1983Flag for Türkiye

asked on

How to optimize Fluent Interface in Web services?

it is my mail class which is a model:

   public class Mail
    {
        public MailService Set { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public List Recipients { get; set; }
        public List Bcc { get; set; }
        public List Cc { get; set; }
        public bool Send { get; set; }
        public Mail()
        {
            Set = new MailService(this);
        }

    }

Open in new window

Also i created a web service which is controller :
namespace MyFluentInterface.Services
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MailService : System.Web.Services.WebService
    {
          [NonSerialized]
          private readonly Mail _mail;
          public MailService()
          {

          }
          public MailService(Mail mail)
        {
            _mail = mail;
        }

        #region IMail Members

        [WebMethod]
          public MailService UserName(string username)
        {
            _mail.UserName = username;
            return this;
        }
        [WebMethod]
        public MailService Password(string password)
        {
            _mail.Password = password;
            return this;
        }
        [WebMethod]
        public MailService Subject(string subject)
        {
            _mail.Subject = subject;
            return this;
        }
        [WebMethod]
        public MailService Body(string body)
        {
            _mail.Body = body;
            return this;
        }
        [WebMethod]
        public MailService Recipients(List recipients)
        {
            _mail.Recipients = recipients;
            return this;
        }
        [WebMethod]
        public MailService Bcc(List bcc)
        {
            _mail.Bcc = bcc;
            return this;
        }
        [WebMethod]
        public MailService Cc(List Cc)
        {
            _mail.Cc = Cc;
            return this;
        }

        [WebMethod]
        public bool Send()
        {
            _mail.Send = true; // Bir olayin sonucunda bu elde edilmeli
            return true;
        }
        #endregion
    }
}

Open in new window

Also i have a VIEW project to test:

    public class Test
    {
        private Mail mail { get; set; }
        public Test()
        {
            mail = new Mail();

        }
        public bool Send()
        {
            return mail.Set.Subject("fdsfs").Body("fsdg").Send();
        }
    }

Open in new window

i utilize from Fluent interface.i used it in web service. But this error returns me:

Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface.

How to solve it?
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of programmerist 1983

ASKER

Not working Sorry :(
ARE YOU THERE?????????????????????????? i want to see answer . i wont refresh my subscribe