Solved

Web Service Overloaded Constructor/Set method

Posted on 2004-09-13
3
291 Views
Last Modified: 2006-11-17
Hi there,
I was writing a mail web service which takes toEmail, fromEmail, smtp server and send an email. But it seems the set web Method that I wrote doesn't work. I tried servericeObj.setToEmail("..."), then called servericeObj.getToEmail() from client, the value wasn't set. I also tried to initialize the service with following overloaded constructor, it didn't work. The last thing I want to do (But I am sure it works) is to call servericeObj.SendEmail(toEmail, fromEmail, smptServer, ...). Can Someone provides me a sample of how to call set WebMethod or Overloaded constructors for web services? The help will be greatly appreciated!

Here is a clip of my code:

   private int intPriority = 0;
   private string strToEmail = "";
   private string strFromEmail = "";
   private string strSubject = "";
   private string strSmtpServer = "";

   public MailService(int iPriority, string sToEmail, string sFromEmail, string sSubject, string sSmtpServer)
  {
          intPriority = iPriority;
          strToEmail = sToEmail;
          strFromEmail = sFromEmail;
          strSubject = sSubject;
          strSmtpServer = sSmtpServer;
  }
  [WebMethod]
  public string getToEmail()
  {
          return strToEmail;
  }
  [WebMethod]
  public void setToEmail(string sToEmail)
  {
         strToEmail = sToEmail;
  }
....

-gvm
0
Comment
Question by:gvmdevelopment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
ID: 12049891
Your idea is right for a stateful, regular object oriented approach.  But on the web everything is stateless.  You are sending state into your overloaded constructor with the arguments, but once the call to instantiate the web service is made, all that state info is gone.  You want to declare a WebMethod that takes all of the args in your ctor, build out the email message and send it and be done.

[WebMethod]
pubilc void sendEmail(string sToEmail, string sFromEmail, string sSubject, string sSmtpServer)
{
     // build out the mail meesage and send.
}

Now, I notice you have priority specified in the argument.  If you want to queue up emails for bulk sending at some future point, you have to save the info in some persistence media (like a database) and then have a separate method to go get that data and send out the email.

John
0
 
LVL 1

Author Comment

by:gvmdevelopment
ID: 12054478
Hi John,
That was what I thought the problem was, thanks a lot for your help!

--gvm
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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