Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Asynchronous Service Problem

 
 
Old 04-17-2006   #1 (permalink)
Vishal


 
 

Asynchronous Service Problem

Hi,

Am trying to create Windows Service using WCF am using Win 2003 OS. But
Service Invocation fails. am not able to figure out the problem it gives
error saying WebDev.WebServer.exe has encounterd a problem and need to close.

Following is my Service Code(Win NT service)
-----------------------------------------------------
[ServiceContract]
public interface IAsyncService
{
[OperationContract]
double Add(double paramOne, double paramTwo);

[OperationContract]
double Multiply(double paramOne, double paramTwo);

}

[RunInstallerAttribute(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller process;
private ServiceInstaller service;

public ProjectInstaller()
{
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = "AsynchronousService";
Installers.Add(process);
Installers.Add(service);
}
}

partial class AsyncService : ServiceBase, IAsyncService
{
public ServiceHost serviceHost = null;

#region Contrsuctor
public AsyncService()
{
InitializeComponent();
ServiceName = "AsyncService";
}
#endregion

#region Main
static void Main(string[] args)
{
ServiceBase.Run(new AsyncService());
}
#endregion

#region On Start

protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost.Dispose();
}


// Get base address from app settings in configuration.
Uri baseAddress = new
Uri(System.Configuration.ConfigurationManager.AppSettings["baseAddress"]);


// Create a ServiceHost for the CalculatorService type and
provide the base address.
serviceHost = new ServiceHost(typeof(AsyncService), baseAddress);


// Open the ServiceHostBase to create listeners and start
listening for messages.
serviceHost.Open();
}
#endregion

#region On Stop
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost.Dispose();
serviceHost = null;
}

}
#endregion

#region IAsyncService Members

double IAsyncService.Add(double paramOne, double paramTwo)
{
Thread.Sleep(6000);
return paramOne + paramTwo;
}

double IAsyncService.Multiply(double paramOne, double paramTwo)
{
Thread.Sleep(6000);
return paramOne * paramTwo;
}

#endregion

}

Service App.Config
----------------------
<appSettings>
<add key="baseAddress"
value="http://localhost:8000/AsynchronousService/Service"/>
</appSettings>

<system.serviceModel>
<services>
<service name="AsynchronousService.AsyncService"
behaviorConfiguration="NTServiceBehavior">

<!-- use base address provided by host -->
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="Binding1"
contract="AsynchronousService.IAsyncService" />

<endpoint address="net.tcp://localhost:9000/AsynchronousService/service"
binding="netTcpBinding"
bindingConfiguration="Binding2"
contract="AsynchronousService.IAsyncService"/>
</service>
</services>

<bindings>
<wsHttpBinding>
<binding name="Binding1" />
</wsHttpBinding>

<netTcpBinding>
<binding name="Binding2" />
</netTcpBinding>
</bindings>

<!--For debugging purposes set the returnUnknownExceptionsAsFaults
attribute to true-->
<behaviors>
<behavior
name="NTServiceBehavior"
returnUnknownExceptionsAsFaults="False" >
</behavior>
</behaviors>

</system.serviceModel>



Following is My Client code(Web Application)
----------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
try
{
AsyncServiceProxy p = new
AsyncServiceProxy("WSHttpBinding_IAsyncService");
p.BeginAdd(Convert.ToDouble(TextBox1.Text),
Convert.ToDouble(TextBox2.Text), AddCallBack, p);
}
catch (Exception ex)
{
throw ex;
}
}

private void AddCallBack(IAsyncResult ar)
{
try
{
double Reslt = ((AsyncServiceProxy)ar.AsyncState).EndAdd(ar);
Label1.Text = Reslt.ToString();
}
catch (Exception e)
{
throw e;
}
}


Please help me on this. Let me know if my code is proper.

Thanks n Regds


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Problem with updating service pack1 to service pack2 Vista installation & setup
Problem with a Service that Fails to Start (Bonjour Service) Vista General
Asynchronous Processing PowerShell
new process should be asynchronous .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46