WCF Discovery working only wcf service called - wcf

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!

Related

Adding a WCF Tcp.net service to IIS for Visual Studio 2013 and how to test it

I am trying to deploy a wcf service I have created in Visual studio.
I am almost positive it is a configuration issue in either the wcf service config or in IIS itself.
The config I am using in the service is as follows:
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CandidateServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="SurveyService.SurveyService" behaviorConfiguration="CandidateServiceBehavior">
<endpoint address="/Survey/SurveyService" binding="netTcpBinding" name="CandidateServiceEndPoint" contract="Prometric.Census.SurveyService.ISurveyService" />
<endpoint address="/Survey/SurveyService/mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
I deployed the service once from visual Studio and pointed a new site on IIS with the following settings pointing to the deployment folder
Then after this within IIS you can see the site is in an unknown status:
It is from here that I can't connect to the service or find if it is running or not. I have tried the command /an : find /i "9015" and found nothing so I assume the service is not even running.
If I where to change the bindings on the WCF service and IIS to use http instead everything works fine. (Should say using http is not an option)
Also on top of not getting the service up and running I'm unsure how to test the service as TCP, Am I able to just add a service reference as you would with a http sefvice? As you can see I am pretty new to the tcp side of things and if I have left out any vital information please let me know so I can inslude it in the question.
This might help you :
https://rohitguptablog.wordpress.com/2011/06/16/configuring-wcf-service-with-nettcpbinding/
I followed this guide to make a net.tcp wcf service and it went smoothly. Also, are you sure that your folder has the required privileges? It can be tricky to use another folder than wwwroot/inetpub

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

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).

WCF web service not working after deployed

I am trying to create a WCF web service which will allow other applications to retrieve a string by making a http request to this service url. I tried publishing the service in IIS and when attempting to browse to it, using the url, it says it
' The resource cannot be found'
when I checked the path to the folder I used the url,
and I get the error
'No protocol binding matches the given address
'http://localhost:xxxx/WcfSampleLibrary/Service1/mex.'
Protocol bindings are configured at the Site level in IIS or WAS configuration'
Here is the directory path of the published folder:
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\WcfSampleLibrary.Service1
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\Web.config
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\bin\WcfSampleLibrary.dll
The web config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfSampleLibrary.Service1" behaviorConfiguration ="mex">
<host>
<baseAddresses>
<add baseAddress = "http://192.xxx.x.xxx/WcfSampleLibrary/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address =""
binding="wsHttpBinding" contract="WcfSampleLibrary.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<endpoint address="http://localhost:xxxx/WcfSampleLibrary/Service1/mex" name="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata httpGetEnabled="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" />
</behavior>
</serviceBehaviors>
</behaviors>
In IIS-hosted WCF services you don't specify a full URI in the address. IIS decides the address. Also the baseAddresses element is completely ignored when hosting in IIS (so remove it from you Web.config). The service's base address is determined by the web site & virtual directory into which your wcf service is placed.Do something like this:
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
Then your address would be http://IIS.SERVER/SiteName/Folder/WcfSampleLibrary.Service1.svc. If you're not sure what the address is, use your IIS Administration tool, select the site that has the service in it, Right-click and choose Advanced -> Browse Site.
Also, I'd turn on httpGetEnabled on your mex behavior--if you want to publish your WSDL. This makes it easier to consume your service as you are developing it:
<behaviors>
<serviceBehaviors>
<behavior name="mex" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
With httpGetEnabled being on, browsing to your service URI will give you an option to see the WSDL.

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.

WCF service stop sending web requests once it's hosted in IIS

I have a WCF service that receive query from a silverlight client and send the query to a Search API (Bing, or Google), process the search results to return those back to the silverlight client.
Everything works find in Visual Studio.
Once I publish the service in IIS, I can access the service endpoint and the silverlight client to talk to the service as well. However, the service does not send any query to the Search API. I opened Fiddler to monitor the traffic. There is no web request send to search API.
Is there any setting in IIS, or firewall, that I neglected?
The web.config is attached below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SiteRankerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SiteRankerBehavior" name="SiteDiscovery.SiteRanker">
<endpoint address="" binding="basicHttpBinding" contract="SiteDiscovery.ISiteRanker">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Thanks
Sarah
Ok, I found the solution here that exactly solved my problem. Basically, I need to add the following to web.config and everything works.
<system.net>
<defaultProxy>
<proxy usessystemdefault="False" proxyaddress="http://your-proxy-name.domain.com:port-number-if-any" bypassonlocal="True" autoDetect="False" />
</defaultProxy>
</system.net>
Why it worked in Visual Studio is still a mystery to me though. Strickly speaking, it worked before in Visual Studio if the Fiddler is running at the same time.