[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HOW TO ACCESS WEB SERVICES PROPERTY?

Posted on 2011-10-24
4
Medium Priority
?
291 Views
Last Modified: 2012-05-12
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?

0
Comment
Question by:programmerist
  • 2
4 Comments
 
LVL 40
ID: 37016347
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
 

Author Comment

by:programmerist
ID: 37016360
can i access internal property? Or can i with WCF?
0
 
LVL 9

Expert Comment

by:raysonlee
ID: 37016444
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 37018261
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question