HOW TO ACCESS WEB SERVICES PROPERTY?

it is my mail class which is a model:

   [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [Serializable] 
    public class MailService : System.Web.Services.WebService
    {
        public Mail 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<string> Recipients { get; set; }
        public List<string> Bcc { get; set; }
        public List<string> Cc { get; set; }
        public bool Send { get; set; }
        public MailService()
        {
            Set = new Mail(this);
        }

    }   

Open in new window


Also i created a web service which is controller :

namespace MyFluentInterface.Services
{
   [Serializable]
    public class Mail
    {

        private readonly MailService _mail;
        public Mail()
        {

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


        public Mail UserName(string username)
        {
            _mail.UserName = username;
            return this;
        }

        public Mail Password(string password)
        {
            _mail.Password = password;
            return this;
        }

        public Mail Subject(string subject)
        {
            _mail.Subject = subject;
            return this;
        }

        public Mail Body(string body)
        {
            _mail.Body = body;
            return this;
        }


        public Mail Recipients(List<string> recipients)
        {
            _mail.Recipients = recipients;
            return this;
        }


        public Mail Bcc(List<string> bcc)
        {
            _mail.Bcc = bcc;
            return this;
        }


        public Mail Cc(List<string> Cc)
        {
            _mail.Cc = Cc;
            return this;
        }



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


    
    }
}

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:

HOW TO ACCESS WEB SERVICES PROPERTY?

CLient side :
   MailService mail = new MailService();
mail.Set.   ????????????? I CAN NOT

Open in new window


How to solve it?

programmeristAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)PresidentCommented:
If you want to access the internal properties, you need to provide a WebMethod that returns an object that has its properties set to the values that you want to return.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
You cannot access properties in a Web Service, only methods. You can have internal properties, but public properties do nothing.

If you need to send and receive data to and from the service, you pass parameter(s) to a method that will return the resulting value(s).

Classes that you need to use in a Web Service should not be designed the same way as regular classes. A Web Service does not provide you with an object the same way as regular classes do. It provides only methods, that perform an operation and return a value or an object containing a group of values.

And contrary to a regular class, a Web Service is stateless, it does not keep the values between calls. You call it, get the return value(s) and that is it. If you call another of its methods, even with the same variable, the values of the internal properties are gone.
0
 
programmeristAuthor Commented:
can i access internal property? Or can i with WCF?
0
 
raysonleeCommented:
You can expose the data using methods like:

<WebMethod()> _
        Public Function GetMachineIPAddress() As String        

         Dim strHostName As String = ""
         Dim strIPAddress As String = ""
         Dim host As System.Net.IPHostEntry        

         strHostName = System.Net.Dns.GetHostName()
         strIPAddress = System.Net.Dns.GetHostEntry(strHostName).HostName.ToString()        

         host = System.Net.Dns.GetHostEntry(strHostName)
         Dim ip As System.Net.IPAddress
         For Each ip In host.AddressList
             Return ip.ToString()
         Next        

         Return ""         

     End Function

Refer to http://www.techrepublic.com/blog/programming-and-development/creating-a-web-service-with-vbnet/519 for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.