Imports System
Imports System.Net
Imports AskTheCIO_082709
Partial Public Class Page
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
'Find the URL we're currently running in (Local DEV, WebDev Staging, Production, etc.)
Dim serviceURI As String = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri
'Add the name of our local proxy web service file to the URL
'In this case, we need a proxy because SharePoint requires HTTP authentication that Silverlight can't handle
serviceURI = serviceURI.Substring(0, serviceURI.LastIndexOf("/")) & "/svcMailer.asmx"'Create an instance of our proxy web service that we defined under Service References
Dim svcmailer As Mailsender.svcMailerSoapClient = New Mailsender.svcMailerSoapClient
'Use the URL we generated to set the endpoint for the proxy web service
svcmailer.Endpoint.Address = New System.ServiceModel.EndpointAddress(New Uri(serviceURI))
'Set the Security Mode of the endpoint to match our SSL usage
If serviceURI.ToLower.Contains("http:") Then
svcmailer.Endpoint.Binding = New System.ServiceModel.BasicHttpBinding(ServiceModel.BasicHttpSecurityMode.None)
Else
svcmailer.Endpoint.Binding = New System.ServiceModel.BasicHttpBinding(ServiceModel.BasicHttpSecurityMode.Transport)
End If'here we create a handler for the data
AddHandler svcmailer.sendmailCompleted, AddressOf receivehandler
'here we send um something....
Try''Fire off our spinner(in Spinner XAML)
'////////////////////////////////////////////
' '////////////////////////////////////////////
svcmailer.sendmailAsync("anotherusername@mmc.org", "username@mmc.org", txt_comments.Text.Trim)
Catch ex As Exception
txt_complete.Text = ex.ToString
End Try
End Sub
Private Sub receivehandler(ByVal sender As Object, ByVal e As MailSender.sendmailCompletedEventArgs)
'display the webservice's return in a text box
Try
txt_complete.Text = e.Result.ToString
grid1_fadeout.Begin()
Catch es As Exception
txt_complete.Text = "XAML Error:" & es.InnerException.ToString
End Try
Exit Sub
End Sub
Private Sub grid1_fadeout_Completed(ByVal sender As System.Object, ByVal e As System.EventArgs)
txt_complete.Visibility = Windows.Visibility.Visible
End Sub
End Class
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Net.Mail
Imports AskTheCIO_082709.Web
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class svcMailer
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function sendmail(ByVal fromAddress As String, ByVal toAddress As String, ByVal txt_comments As String) As String
Try'check boxes
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(fromAddress)
mail.To.Add(toAddress)
'set the content
mail.Subject = "From Ask the CIO Webform"'to embed images, we need to use the prefix 'cid' in the img src value
'the cid value will map to the Content-Id of a Linked resource.
'thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
' removed width=""275"" ""height=75""
Dim strBody As String'Lets format the body text,
strBody = "<html>" & vbNewLine & _
"<body><img src=cid:companylogo><br>" & vbNewLine & _
"<br><b>" & "Comments: </b>" & "<br>" & txt_comments & _
"</body>" & vbNewLine & _
"</html>"Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(strBody, Nothing, "text/html")
'create the LinkedResource (embedded image)
Dim logo As New LinkedResource(My.Request.MapPath("MH_Logo.png"))
logo.ContentId = "companylogo"'add the LinkedResource to the appropriate view
htmlView.LinkedResources.Add(logo)
'add the views
mail.AlternateViews.Add(htmlView)
'send the message
Dim smtp As New SmtpClient("mail.mmc.org") 'specify the mail server address
smtp.Send(mail)
Return"Message Sent!"Catch ex As Exception
Return"There was a problem sending your message:" + vbCrLf + ex.Message
End Try
End Function
End Class
Only thing I can think is that the send button is being clicked twice before the message is done being sent. Maybe add a boolean variable boolOkToSend to your project. In the button press event only send the email if the boolOkToSend is true
Dim boolOkToSend as boolean=true
13 Private Sub btn_submit_Click(ByVal sender
As System.Object,
ByVal e As System.Windows.RoutedEventArgs)
14 'Find the URL we're currently running in (Local DEV, WebDev Staging, Production, etc.)
If Not boolOkToSend then
return
else
boolOkToSend = false
end if
etc..
56 Private Sub receivehandler(ByVal sender
As Object, ByVal e
As MailSender.sendmailCompletedEventArgs) 57 'display the webservice's return in a text box 58 Try 59 txt_complete.Text = e.Result.ToString 60 grid1_fadeout.Begin() 61 Catch es As Exception 62 txt_complete.Text = "XAML Error:" & es.InnerException.ToString 63 End Try 64 boolOkToSend = true 65 66 Exit Sub 67 End Sub
15 Dim serviceURI
As String = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri
SMTP Server (like the one that could be the guilty).
I would say, let's check first which part is the offending one (try in this order):
Create a console application and send an email using your code, got two emails? (SMTP Server offending).
Create a dummy app that calls your service (even ad dummy SL page, onLoad... or something like that). Got twice? (Service call issue).
Silverlight, mmm... a dummy test to check whether the button is called twice add a member varialbe, set it to zero, each time the button click code is run increment by one the varialbe (show a message if the varialbe has a value greater than one).
Once we know for sure where is the error we can check how to proceed.
rgouette
Member
7 Points
105 Posts
Why is my project sending two e-mails?
Aug 28, 2009 03:49 PM | LINK
Hi lads, my Silverlight 2.x / .asmx app is sending two e-mails when I'm clicking the send button once.
I stepped through th code, but saw nothing that caught my eye..
page.xaml below, followed by page.xaml code behind follows , then service code behind.
Ken Tucker
All-Star
23250 Points
3534 Posts
Re: Why is my project sending two e-mails?
Aug 29, 2009 10:54 AM | LINK
Only thing I can think is that the send button is being clicked twice before the message is done being sent. Maybe add a boolean variable boolOkToSend to your project. In the button press event only send the email if the boolOkToSend is true
Dim boolOkToSend as boolean=true
13 Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
14 'Find the URL we're currently running in (Local DEV, WebDev Staging, Production, etc.)
If Not boolOkToSend then
return
else
boolOkToSend = false
end if
etc..
56 Private Sub receivehandler(ByVal sender As Object, ByVal e As MailSender.sendmailCompletedEventArgs)57 'display the webservice's return in a text box
58 Try
59 txt_complete.Text = e.Result.ToString
60 grid1_fadeout.Begin()
61 Catch es As Exception
62 txt_complete.Text = "XAML Error:" & es.InnerException.ToString
63 End Try
64 boolOkToSend = true
65
66 Exit Sub
67 End Sub
15 Dim serviceURI As String = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUriSpace Coast .Net User Group
Brauliod
Contributor
2448 Points
744 Posts
Re: Why is my project sending two e-mails?
Aug 29, 2009 02:59 PM | LINK
Mmmm...
The issue can come from three different sources:
I would say, let's check first which part is the offending one (try in this order):
Once we know for sure where is the error we can check how to proceed.
Good luck
Braulio
Book: Mastering LOB Development for Silverlight 5: A Case Study in Action
Brauliod
Contributor
2448 Points
744 Posts
Re: Re: Why is my project sending two e-mails?
Aug 29, 2009 03:03 PM | LINK
Another thing that will help: laucnh fiddler and check if there are two calls to the service when you click on the button.
Book: Mastering LOB Development for Silverlight 5: A Case Study in Action
rgouette
Member
7 Points
105 Posts
Re: Re: Re: Why is my project sending two e-mails?
Aug 31, 2009 04:04 PM | LINK
The source of the issue has been identified.
Thanks lads for your help.
The issue was ..um...programmer induuced..
Suffice it to say, it was normal behaviour....
[:$]