![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with a Service that Fails to Start (Bonjour Service) | Stéphane Bergeron | Vista General | 2 | 07-11-2008 06:21 PM |
| Asynchronous Processing | Ozone | PowerShell | 7 | 06-09-2008 10:27 AM |
| asynchronous serial i/o | Martijn | .NET General | 2 | 05-18-2008 11:11 AM |
| new process should be asynchronous | pantagruel | .NET General | 0 | 03-31-2008 08:55 AM |