Meenu gk

Meenu gk

  • NA
  • 4
  • 4.4k

service check

Jun 1 2011 1:02 PM
Please help me to write an error checking webservice code, which will send an email if any error is found in the service…The url of the webservice and email details are given in the app.config file…I am a beginner in coding...i need console application (program.cs)



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Net;

using System.Diagnostics;

using System.Data;

using Microsoft.Win32;

using System.Configuration;

using System.Collections.Specialized;

using System.Net.Mail;

using System.Web;

using System.Web.Services;

using System.ComponentModel;

namespace Check_Service

{

class Webservice

{

static void Main(string[] args)

{

SendEmail();

}





private static void SendEmail()

{

try

{



MailMessage mail = new MailMessage();

string strEmails = ConfigurationManager.AppSettings["notifyEmails"];

mail.From = new MailAddress("[email protected]");

mail.To.Add(new MailAddress(strEmails));

mail.Subject = "This is a sample email";

mail.Body = "this is the body of the mail";

new SmtpClient().Send(mail);



}

catch {

Console.WriteLine("Exception caught in process");

Console.ReadLine();

}





}

}

}







The app.config file



<?xml version="1.0" encoding="utf-8" ?>

<configuration>



<configSections>

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e198" >

<section name="ConsoleApplication2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral " requirePermission="false" />

</sectionGroup>

</configSections>



<appSettings>

<add key="notifyEmails" value="[email protected]"/>

<add key ="URLS" value="http://smtptest/services/webservice.asmx" />

</appSettings>



<bindings>

<basicHttpBinding>

<binding name="ServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"

receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"

bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

maxBytesPerRead="4096" maxNameTableCharCount="16384" />

<security mode="None">

<transport clientCredentialType="None" proxyCredentialType="None"

realm="" />



</security>

</binding>

</basicHttpBinding>

</bindings>



<system.serviceModel>

<client>

<endpoint address="http://smtptest/services/webservice.asmx" binding="basicHttpBinding" bindingConfiguration="serviceSoap"

contract="Service.serviceSoap" name="serviceSoap" />

</client>

</system.serviceModel>



<applicationSettings>

<ConsoleApplication20.Properties.Settings>

<setting name="ConsoleApplication2_ServiceReference_service" serializeAs="String">

<value> http://smtptest/services/webservice.asmx</value>

</setting>

</ConsoleApplication20.Properties.Settings>

</applicationSettings>



</configuration>

Answers (1)