?
Solved

Web Service Overloaded Constructor/Set method

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

777 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