Reputation: 93
I am facing the problem with WCF self hosting application while trying to run with the following configuration:
<system.serviceModel>
<services>
<service name="statisticsCollectingService">
<endpoint address="net.tcp://localhost:8200/RadioStatistics/"
binding="netTcpBinding"
contract="RadioStatistics.Services.IStatisticsCollectingService" />
<endpoint address="http://localhost:8100/RadioStatistics/"
binding="basicHttpBinding"
contract="RadioStatistics.Services.IStatisticsCollectingService" />
</service>
<service name="biDataExportService">
<endpoint address="net.tcp://localhost:8001/RadioStatistics/"
binding="netTcpBinding"
contract="RadioStatistics.Services.IBIDataExportService" />
</service>
</services>
</system.serviceModel>
The exception occurs as follows:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': The process cannot access the file because it is being used by another process ---> Spring.Objects.Factory.ObjectCreationException: Error creating object with name 'statisticsCollectingServiceHost' defined in 'config [C:\TTL\zer_rel_12_1_main_TTL_C1077\TTL\CommonTools\RadioStatistics\bin\Debug\RadioStatistics.ServerApp.vshost.exe.Config#spring/objects] line 4' : Initialization of object failed : HTTP could not register URL http://+:8000/RadioStatistics/services/ because TCP port 8000 is being used by another application. ---> System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL http://+:8000/RadioStatistics/services/ because TCP port 8000 is being used by another application. ---> System.Net.HttpListenerException: The process cannot access the file because it is being used by another process
at System.Net.HttpListener.AddAll()
at System.Net.HttpListener.Start()
at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at Spring.ServiceModel.Activation.ServiceHostFactoryObject.AfterPropertiesSet() in l:\projects\spring-net\trunk\src\Spring\Spring.Services\ServiceModel\Activation\ServiceHostFactoryObject.cs:line 176
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:line 1264
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:line 1860
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:line 884
--- End of inner exception stack trace ---
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:line 901
at Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:line 2097
at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:li
Running a Windows XP SP3 was already trying to do the following:
httpcfg set urlacl /u http://+:8100/RadioStatistics/ /a "D:(A;;GX;;;BU)"
(with I guess all possible variants of general grants and/or users - like DU (for domain users?)
Also trying to add to the IP list
httpcfg set iplisten -i 0.0.0.0:8100
This was after I've found an event in the event log:
Unable to bind to the underlying transport for 0.0.0.0:8100. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine. The data field contains the error number.
The worst is that it was already working in the past (before I went on holidays few weeks ago). The machine seems unchanged to me as it was not being touched. But the error drives me crazy. The worst thing is that the error occurs regardless the choosen port.
Of cource it works absolutely fine after the basicHttpBinding is removed.
TIA
Roland
Upvotes: 6
Views: 11062
Reputation: 117
This problem is solved by right clicking on your Visual Studio application icon and selecting "Run as administrator".
Here's an excerpt from the Microsoft official documentation page:
The service must be run with administrator privileges. Because you opened Visual Studio with administrator privileges, when you run GettingStartedHost in Visual Studio, the application is run with administrator privileges as well. As an alternative, you can open a new command prompt as an administrator (select More > >Run as administrator from the shortcut menu) and run GettingStartedHost.exe within it.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/how-to-host-and-run-a-basic-wcf-service
You may need to change the port number as well.
Upvotes: 0
Reputation: 3669
@Roland, I know this is a very old post and I have seen you asking this on other sites as well. I have recently had this problem for a very long time. Eventually I have two ways of resolving this. 1) Though this is probably not the recommended way, get local admin permission on the account that runs the window service. This is why when people run VS as admin this problem goes away on their local machine because HTTP by default grants permission to local admin.
2) As you said, use httpcfg on xp/2003 server to configure the url and port number like you did; worth mentioning that "D:(A;;GX;;;LS)"
is the correct SDDL that worked for me; I tried others but didn't work. Equally importantly, don't include the service name when configuring just use httpcfg set urlacl -u http://+:portnumber -a D:(A;;GX;;;LS)"
. And don't configure iplisten with httpcfg as this will most likely prevent IIS running on the server. The error you got from the event log: "Unable to bind to the underlying transport for 0.0.0.0:8100. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine. The data field contains the error number" suggests that IIS is stopped. In fact if you do httpcfg query iplisten
you should only see the default ipaddress 0.0.0.0. After configuring the url using httpcfg you need to restart http with net stop http
and wait for everything to stop successfully. Then do net start http
. If http couldn't stop properly you need to reboot the server after which IIS should be running (if you had deleted any invalid ipaddress). Then start your window service and check with netstat -an | findstr "0.0:yourportnumber"
if there is a result then that means your window service is working now.
Just to add, I have followed the instructions on our first dev server and it didn't work initially because 1) I added iplisten and 2) I didn't restart http after configuring the url. 3) I didn't check to make sure iis was running properly. Hope this helps somehow.
Upvotes: 0
Reputation: 366
I believe this has to do with configuring the service in .NET 3.5 and then changing to .NET 4.0 - the service configuration defaults have changed radically, and now by default many endpoints are created. http://blogs.msdn.com/b/endpoint/archive/2009/06/30/service-configuration-improvements-in-net-4.aspx
Upvotes: 0
Reputation: 65391
You may have something else listening on the same port. Try running
netstat -o -n -a
to get a list of all the processes and what they are listening for.
Upvotes: 6