Hello,
I'm working on an ASP.NET application that i want to host using WCF using "basicHttpBiniding" . The hosting should be done in a windows service. I've did a test by hosting the service in a console application (instantiating a ServiceHost in a console application project), everything worked fine.
The same project is now transferred to be a windows service, i receive an exception "There was no endpoint listening at http://localhost:8000/HelpDesk/HelpDeskService that could accept the message. This could be caused by an incorrect address or SOAP action, among other things." Debugging teh service shows no errors but the listening ports aren't opened. The installed windows service has an administrative authentication thus no security issue might be involved here.
I guess there is nothing wrong with the wcf contracts & generated proxies because evrything goes fine when hosted in a console application, so what considerations should be taken if it is hosted in a Windows Service.
Does anyone knows the problem or worked with hosting wcf in a windows service please i would appreciate much if u provide me with sample applications or helpful links.
for any further explanation about the problem, this is my email-address : taha_zeina@hotmail.com
Thanks,
Zeina

Hosting WCF in a Windows Service?? "No endpoint listening exception"
phpcs
You can open the config file using the SvcConfigEditor.exe utility which comes with the SDK (right click on the config file in VS and select "Edit WCF configuration).
Inside the editor there is a node called "diagnostics", the fastest way to setup tracing is to check the "default tracing" checkbox.
ChandraT
I have been trying to run the client and service programs on two different machines
which have different IP addresses. I was to run them on the same machine without any errors.
But different machines i got this error
Unhandled Exception: System.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.
here are my config files
Service
< xml version="1.0" encoding="utf-8" >
<configuration>
<system.serviceModel>
<services>
<service
name="ProgrammingIndigo.ParcelService"
behaviorConfiguration="ParcelServiceBehavior">
<endpoint
address="http://172.29.188.102:8000/ParcelService/"
binding="wsHttpBinding"
bindingConfiguration="ParcelServiceBinding"
contract="ProgrammingIndigo.IParcelService" />
<endpoint
address="http://172.29.188.102:8000/ParcelService2/"
binding="wsHttpBinding"
bindingConfiguration="ParcelServiceBinding"
contract="ProgrammingIndigo.IParcelService2" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="ParcelServiceBinding">
<reliableSession enabled="true"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<behavior
name="ParcelServiceBehavior"
returnUnknownExceptionsAsFaults="true" >
</behavior>
<behavior
name="ParcelServiceBehavior2"
returnUnknownExceptionsAsFaults="true" >
</behavior>
</behaviors>
</system.serviceModel>
</configuration>
For the client config is
< xml version="1.0" encoding="utf-8" >
<configuration>
<system.serviceModel>
<client>
<endpoint
name="ParcelServiceEndpoint"
address="http://192.168.2.45:8000/ParcelService/"
binding="wsHttpBinding"
bindingConfiguration="ParcelServiceBinding"
contract="ProgrammingIndigo.IParcelService" />
<endpoint
name="ParcelService2Endpoint"
address="http://192.168.2.45:8000/ParcelService2/"
binding="wsHttpBinding"
bindingConfiguration="ParcelServiceBinding"
contract="ProgrammingIndigo.IParcelService2" >
</endpoint>
</client>
<bindings>
<wsHttpBinding>
<binding name="ParcelServiceBinding" >
<reliableSession enabled="true"/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Please let me know where to make the necessary changes in hte code.
I am very new to this programming. This is a sample program from Programming Indigo
but i repeat, i need to run this on two different machines/IP Address.
Thank you
Sree
conzero
Hi Scott,
please can u illustrate to me what is a "server trace" & how can i do it.
I'm new in development & i didn't worked with this before & i find no usefull links to start with it.
so please can u give me more info about the considered issue.
thanks so much
Syed Usama KHalid
gotech.voip
Thanks so much Adiavn,
I worked with it & it was fine i was able to trace the activities of the WCF service.
Moreover, i made a comparison of the trace between Windows Service & Console Aplication hosting, the difference is at the action of the OperationContract.
In a console application, when a message was written, an http request was sent where as in the Windows Service, when a message was written, an exception is thrown indicating that it has failed to send the message over http due to the fact that it hadn't find a lsitening endpoint.
Again i couldn't find out why things are working pretty well with the Console host where it gives exception in the Windows Service Hosting although the same is being done in both ways.
Are there any special code lines that should be added to make the http channel accessible from the WIndows Service to the Web Site Client
Please, i'll appreciate much if i could have a curing answer, because this is driving me crazy especially that this is my senior project & i have a close deadline to present it to my university
PLEASE HELP
Thanks alot in advance
Wolfgang Kaml
I really don't know how to thank u, it worked everything worked soooooo nice.
u r gorgeous, that was it. The using part. It closes the host at its end.
Thousands & millions thanks
Take care
Bye
TheBenZ
I'm working on my local machine, & there is no firewall.
gisem
This section seems to be the problem:
using (ServiceHost host = new ServiceHost(
serviceType,
baseAdresses))
{
host.Open();
wf.StartWorkflowRuntime();
timer.Start();
}
The minute the using block end the servicehost is closed, so try creating it without the using block:
ServiceHost host = new ServiceHost(serviceType, baseAdresses);
host.Open();
wf.StartWorkflowRuntime();
timer.Start();
Also, I don't know the exact implementation you are using, but to me it seems more logical to set the timer.enabled to "true" at the end of the method.
You may also find this link interesting:
http://windowssdk.msdn.microsoft.com/en-us/library/ms733069(VS.80).aspx
John Hart_MS
chaminda perera
Thanks Hilton for ur reply.
First, the mispelling is just in the current context, i didn't copy it from the Config file. Second, there are no errors in the event log, only informational events indicating that the service has started successfully & is running.
it is much weird because everything worked fine when it was hosted in a console application.
This is the resulting error in the web page.
Server Error in '/HelpDeskSite' Application.
--------------------------------------------------------------------------------
No connection could be made because the target machine actively refused it
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
Source Error:
Line 112: public string StartWorkflowInstance()
Line 113: {
Line 114: return base.InnerProxy.StartWorkflowInstance();
Line 115: }
Line 116:
Source File: c:\Inetpub\wwwroot\HelpDesk\HelpDeskSite\App_Code\Client.cs Line: 114
Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +369
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +421
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetRequestStream() +895
System.ServiceModel.Channels.WebRequestHttpOutput.GetOutputStream() +42
[EndpointNotFoundException: There was no endpoint listening at http://localhost:8000/HelpDesk/HelpDeskService that could accept the message. This could be caused by an incorrect address or SOAP action, among other things.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +1780354
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +826
IWorkflowServices.StartWorkflowInstance() +0
WorkflowServicesProxy.StartWorkflowInstance() in c:\Inetpub\wwwroot\HelpDesk\HelpDeskSite\App_Code\Client.cs:114
_Default.btnSubmit_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\HelpDesk\HelpDeskSite\Customer\Default.aspx.cs:43
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921
Help please, because this is so weird & i can't figure the solution out.
Thanks
ThompsonMcG
This is the App.Config of the Windows Service:
< xml version="1.0" encoding="utf-8" >
<configuration>
<connectionStrings>
<add name="ConnString" connectionString="Data Source=DPESRV2003-VPC;Initial Catalog=HelpDeskDB;Integrated Security=True"/>
<add name="ConnStringTrack" connectionString="Data Source=DPESRV2003-VPC;Initial Catalog=TrackingStore;Integrated Security=True"/>
</connectionStrings>
<appSettings>
<add key="HTTPBaseAddress" value="http://localhost:8000/HelpDesk/"/>
<add key="TCPBaseAddress" value="net.tcp://127.0.0.1:81/HelpDesk/"/>
</appSettings>
<system.serviceModel>
<services>
<service type="HelpDesk.Communication.WorkflowServices">
<endpoint
address="HelpDeskService"
binding="basicHttpBinding" contract="HelpDesk.Communication.IWorkflowServices"/>
</service>
</services>
</system.serviceModel>
</configuration>
This is the OnStart method of the Windows Service:
protected override void OnStart(string[] args)
{
timer = new System.Timers.Timer(interval);
timer.Elapsed += new System.Timers.ElapsedEventHandler(ServiceTimer_Tick);
timer.AutoReset = true;
timer.Enabled = true;
System.Runtime.Remoting.RemotingConfiguration.Configure(ConfigFile, true);
Type serviceType = typeof(HelpDesk.Communication.WorkflowServices);
string httpBaseAddress =
ConfigurationManager.AppSettings["HTTPBaseAddress"];
string tcpBaseAddress =
ConfigurationManager.AppSettings["TCPBaseAddress"];
Uri httpBaseAddressUri = new Uri(httpBaseAddress);
Uri tcpBaseAddressUri = new Uri(tcpBaseAddress);
Uri[] baseAdresses = new Uri[] {
httpBaseAddressUri,
tcpBaseAddressUri};
using (ServiceHost host = new ServiceHost(
serviceType,
baseAdresses))
{
host.Open();
wf.StartWorkflowRuntime();
timer.Start();
}
}
And finally this is the Client Web.Config:
< xml version="1.0" >
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<dataConfiguration defaultDatabase="ConnString"/>
<appSettings/>
<connectionStrings>
<add name="ConnString" connectionString="Data Source=DPESRV2003-VPC;Initial Catalog=HelpDeskDB;Integrated Security=True;" providerName="System.Data.SqlClient" />
<add name="ConnStringTrack" connectionString="Data Source=DPESRV2003-VPC;Initial Catalog=TrackingStore;Integrated Security=True"/>
</connectionStrings>
<system.serviceModel>
<client>
<endpoint name="HelpDeskConfiguration" address="http://localhost:8000/HelpDesk/HelpDeskService" bindingConfiguration="BasicHttpBinding_IWorkflowServices" binding="customBinding" contract="IWorkflowServices"/>
</client>
<bindings>
<customBinding>
<binding name="BasicHttpBinding_IWorkflowServices">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11Addressing1" writeEncoding="utf-8"/>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" mapAddressingHeadersToHttpHeaders="true" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/>
</binding>
</customBinding>
</bindings>
</system.serviceModel>
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms">
<forms name="Login" loginUrl="Login.aspx">
</forms>
</authentication>
<authorization>
<deny users=" "/>
</authorization>
<compilation debug="true" defaultLanguage="c#">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<membership defaultProvider="AspNetSqlProviderRamzi">
<providers>
<add connectionStringName="ConnString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" description="Stores and retrieves membership data ..." name="AspNetSqlProviderRamzi" type="System.Web.Security.SqlMembershipProvider"/>
</providers>
</membership>
</system.web>
</configuration>
cristib
If you set up a trace for your server you should see the 'listen at xxx' activity. You should do that to verify the enpoints.
Thanks!
Scott
aquino
Aside from the 'using' statement, the 'host' variable is local to the OnStart method. It will need to be global, e.g.:
private ServiceHost host;
protected override void OnStart(string[] args)
{
...
host = new ServiceHost(serviceType, baseAdresses);
host.Open();
// Perhaps write a successful Open to the event log
...
}
Also, have you got a 'host.Close();' in the service stop method
Jamie Garbutt