Solved

Web Service Overloaded Constructor/Set method

Posted on 2004-09-13
3
287 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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