Solved

Web Service Overloaded Constructor/Set method

Posted on 2004-09-13
3
281 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
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
Comment Utility
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
Comment Utility
Hi John,
That was what I thought the problem was, thanks a lot for your help!

--gvm
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now