WCF Service Hosted in Windows Service Throwing Exception When Deployed On Server - wcf

I have a WCF Service library that I have hosted in a Windows Service. Both projects are using .NET Framework 4.5. I have copied WCF Service configuration into Windows Service “app.config”. For reference the config in windows service project looks:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <connectionStrings>
<add name="SmartDataExchangerContext" connectionString="Data Source=(local)\SQLExpress; Initial Catalog=SmartDataExchanger; Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel>
<services>
<service name="SmartDataExchangerService.SchoolService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SmartDataExchangerService/SchoolService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="SmartDataExchangerService.ISchoolService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="127.0.0.1" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="SmartDataExchangerService.UserService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SmartDataExchangerService/UserService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="SmartDataExchangerService.IUserService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel> </configuration>
I am installing the service on development machine using following command:
“InstallUtil.exe” “C:\Test\MyServiceHost.exe”
The service is getting installed successfully. Also I am able to consume the WCF service on development machine. So everything working as expected on development machine.
Now I am trying to install this windows service on Windows Server 2008 R2 machine. I am following these steps:
Copied “Dubug” folder content of Windows Service project from
development machine onto server.
Opened a command prompt in administrator mode.
Run the command:
“InstallUtil.exe” “C:\Test\MyServiceHost.exe”
On execution above command returns following error:
Exception occured while initializing the installation:
System.ArgumentException: Invalid directory on URL..
I have so far made following attempts:
Removed element from config file as suggested in inline
comment.
Change the startup object to ServiceName.Program.
Instead of using localhost, I tried using machine public IP
Address.
Checked my WCF Service is not using any file from local drive
i.e. no use of “C:\” or “D:\”.
Can someone suggest any step I should try to solve this issue.
UPDATE:
The issue is solved. I restarted the PC, performed the steps a fresh and it got solved. I suspect I was not giving correct path while executing the command (silly me).

Related

WCF Discovery working only wcf service called

Ok let's start.
I make wcf service and publish it in IIS 7.5 via Visual Studio 2012.
The service is running and works well when I use WCF test client.
To enable UDP discovery, i make some adjustment on app.config as follow:
<system.serviceModel>
<services>
<service name="System_Core.wcf_service">
<endpoint address="" binding="wsHttpBinding" contract="System_Core.IWCF_Service" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint isSystemEndpoint="true" kind="udpDiscoveryEndpoint" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceDiscovery />
</behavior>
</serviceBehaviors>
</behaviors>
That file also copied to web.config when publish. In short, the wcf service itself works good.
The problem is this:
I make another project which need to discover wcf service on network. But the discovery only works AFTER first calling or navigate manually to the .svc in the browser. When I restart the IIS or wcf in IIS7 manager, discovery back to failed/no any response received. It seems the wcf is not automatically started. I check on IIS config it start automatically. The site itself also set to start automatically. I even put some of these line in applicationHost.config base on some receommendation on the web:
<site name="WCF" id="1" serverAutoStart="true">
<application path="/" serviceAutoStartEnabled="true" >
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\WCF" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8888:" />
</bindings>
</site>
<applicationPools>
<add name="DefaultAppPool" startMode="AlwaysRunning" managedRuntimeVersion="v4.0" />
<add name="ASP.NET v4.0" managedRuntimeVersion="v4.0" />
<add name="ASP.NET v4.0 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
<applicationPoolDefaults>
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
</applicationPoolDefaults>
</applicationPools>
Still didn't work! IIS said it 'Started', Site said it 'Started', but discovery still only works after when the service .svc file called manually in the browser. When you restart the server or site, it backs to not work. I believe any service SHOULD be start when IIS start, but it won't.
I found on the internet some others have same problem and still no resolve.
I give up and skip all the confusing and install the initialization page extension for IIS, described by the great Schwammy in this page:
http://www.schwammysays.net/auto-starting-websites-on-iis-7-5/
It works great, simple!

Generate a svc / wsdl URL in my WCF web service

Usually when i implement a 3rd party WCF web service then i get a URL that ends with an .svc extension.
I just created a WCF Web Service in VS2010 and i'm able to run that service, but i don't see any URL in the Test Client that ends with a .svc extension.
Is there something else i need to do in order to get such a URL? Because usually from there people are able to get the WSDL also by adding ?wsdl to the end like:
http://site.com/service1.svc?wsdl
How can i generate such a URL in my Web Service?
This is what i have in my App.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="TestWebservice.Test">
<endpoint address="" binding="wsHttpBinding" contract="TestWebservice.ITest">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/TestWebservice/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Edit
I removed the mexHttpBinding endpoint from my configuration file. When i launch my Web Service now it automatically shows a URL to a WSDL:
http://localhost:8732/Design_Time_Addresses/TestWebservice/?wsdl
The / before the ?wsdl part seems to be very important. Otherwise it won't work.
But that still leads me to my last question. How can i specify the URL to the .svc file? I'd like to have a URL like: http://localhost:8732/Design_Time_Addresses/TestWebservice/Test.svc?wsdl
Edit 2
I got a bit further. I read this: http://msdn.microsoft.com/en-us/library/aa751792.aspx
So i created a Test.svc file in the root of my project with the following code:
<% #ServiceHost Service="TestWebservice.ITest" %>
Then i tried to access my svc file through the following URLs, but both didn't work for me:
http://localhost:8732/Design_Time_Addresses/TestWebservice/Test.svc
http://localhost:8732/Design_Time_Addresses/Test.svc
Is it even possible to host a svc inside Visual Studio? Or do i really need to host it in IIS first?
Edit 3 - Fixed!
I finally have it working! I re-added the mexHttpBinding to my App.Config.
I installed IIS7. Published the Web Service to a folder in my C:\ drive. Then mapped that folder in IIS and tried to request the .svc file in the browser.
At first it didn't work for me because it didn't recognize the .svc extension. Then all i had to do was enter the following cmd: aspnet_regiis.exe -i and now everything works fine.
Everything seems to be working fine now. Guess you can't request a .svc file when the service is hosted by Visual Studio. But it works when its hosted in IIS.

WCF design_time_address not displaying within visual studio 2010

I currently have a wcf service library project that includes my service contract & implementation. If I were to go to a web project within the same solution and add a service reference and click on the discover button, I can see my service listed as http://..design_time_address/myservice listed.
Now if i were to go ahead and move my service contract & implementation classes to another project & configure my wcf library project to point to this new project, I'm finding that when i go and try to discover the service within my web application, I'm not seeing the design_time_address anymore. It's not discovering anything..
Here's what my app.config for the wcf service looked like before I moved the classes to a new project
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="Test.Server.Wcf.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/Test.Server.Wcf/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="Test.Server.Wcf.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
and here's what it looks like after the move
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="Test.Server.Core.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/Test.Server.Wcf/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="Test.Server.Core.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
What am I doing incorrectly? Any help would be greatly appreciated. I've been stuck on this for hours now and I feel like I'm losing my mind...
Thanks
The Discover option you use to add a service reference is an internal visual studio function. What is does is start and list the WCF services it can actually find an implementation for. For some reason it wants to find the implementation of the service interface in a WCF project type (library or application) with a config file. So if you moved you implementation to the Core project being a regular class library without app.config file, it will not Discover your service anymore.
What you can do is start your service manually and browser to the URL to add a service reference. It is just the discovery option that does not work anymore.

Hosting a WCF service with Net.TCP

I am totally new to this and trying to host the simplest WCF service with a net.tcp binding
I have Windows 7 Professional and IIS7 and have enabled NON http activation.
I start a new WCF Service application
project in vs2010 and compile it.
NOHTING ELSE!
I delete all my IIS
Websites and add a new called WCFHost
I open up WcfTestClient.exe and adds
http://localhost/Service1.svc the application finds it
The Web.config looks like this (untouched)
<system.serviceModel>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
So far, so good. But what about that net.tcp binding. I add the "enabledProtocols" attribute so my applicationHost.config looks like this
<site name="WCFHOST" id="3">
<application path="/" applicationPool="WCFHOST" enabledProtocols="http,net.tcp,net.pipe,net.msmq">
<virtualDirectory path="/" physicalPath="C:\Prosjekter\temp\TestService\TestService" />
</application>
<bindings>
<binding protocol="net.tcp" bindingInformation="808:*" />
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
Then I go to the IIS WCFHost website and add binding net.tcp 808:*
And then I modify my web.config for the WCF Service to look like this. (just changed the binding on the endpoints)
<system.serviceModel>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="netTcpBinding" contract="WcfService2.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
When I now try to add the service net.tcp://localhost:808/Service1.svc in my WcfTestClient.exe I get the error
Error: Cannot obtain Metadata from net.tcp://localhost/Service1.svc
TCP-errorcode 10061: No connection could be made because the target machine actively refused it.... 127.0.0.1:808
My firewall is turned off.
I have seen one thing, though.. when using netstat -a the 808 port is not listed there.. should it?
Can someone help me just creating my first WCF service with nettcp binding?
As Tocco says, check that the service is running. You can do this by checking:
netstat /an | find /i "808 "
And it should show:
TCP 0.0.0.0:808 0.0.0.0:0 LISTENING
TCP [::]:808 [::]:0 LISTENING
if the service is running correctly.
To get it to start if it's not already working, you can issue:
sc start NetTcpActivator
from the command line to ttry to start it.
Even before that, make sure that the non-HTTP activation windows components are installed.
Also check that the services are actually running. I had a problem where they would not necessarily start after a reboot.
The net.tcp bindings are enabled on IIS for requests on 808?
Check it on IIS manager / bindings.
See it
I had the same error message and resolved it by not only creating a TCP binding on the site as follows:
But also enabling the net.tcp protocol in Advanced Settings:

Exposing WCF Services Via HTTP when not hosted in IIS

Like the title says, we need to set up WCF services between a .NET app, and a Adobe AIR app. We don't want to run IIS on the machine, and would much prefer to install and run the WCF services hosted within a windows service.
However, I am uncertain of doing that will let us use HTTP as the transport, of does that only work within IIS? I was able to set things up to use the TCP transport, but that doesn't interop with AIR nearly as nice as using HTTP.
EDIT: Some test code I've been using to see if this works:
Regular console app:
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(TestService)))
{
host.Open();
}
Console.WriteLine("Waiting...");
Console.ReadLine();
}
TestService is a simple HelloWorld type service.
In the App.Config:
<configuration>
<system.serviceModel>
<services>
<service name="WCFExample2.TestService" behaviorConfiguration="WCFExample2.TestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WCFExample2/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WCFExample2.ITestService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFExample2.TestServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
You should have no trouble setting up a Windows NT Service which hosts your WCF service and exposes HTTP endpoints - no need for IIS (but the WCF runtime will use the http.sys kernel mode driver).
Have you tried and failed? If so - can you show us what you had, and how and where it failed?
As a bare minimum, you'd probably want to have something like this config on your service side:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Default"
sendTimeout="00:05:00"
maxBufferSize="500000"
maxReceivedMessageSize="500000" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Namespace.MyWCFService"
behaviorConfiguration="Default">
<host>
<baseAddresses>
<add baseAddress="http://MyServer:8282/MyWCFService/"/>
</baseAddresses>
</host>
<endpoint
address="basic"
binding="basicHttpBinding" bindingConfiguration="Default"
contract="Namespace.IMyWCFService" />
</service>
</services>
</system.serviceModel>
Of course, you might need to tweak things like the timeout settings, buffer size settings etc. on your binding, the security mode, and quite possibly other settings as you need them to be.
Marc
You could skip all the config and use the WebServiceHost class (which will do it all for you in a fairly standard way). Get that working then look into tailoring the config manually to meet any extra requirements you may have.
All the info you need is here WebServiceHost on MSDN it's a very straightforward way to get started on a custom (i.e. non IIS) hosted http service.
Mike
Apart from the config file settings one more thing to consider.
If you selfhost in a windows service, a http endpoint then
Make the service login account a local admin on the machine
or
You have to register the service account for the http namespace with http.sys.
This step has to be done by a local admin but only once in each machine. You can use the HttpSysCfg tool to do this in XP/win 2003. For vista/win 2008 use netsh.