Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Web Service Overloaded Constructor/Set method

Posted on 2004-09-13
3
Medium Priority
?
300 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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