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

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

Related

My WCF Service can't run because because the target machine actively refused it 127...:6414

I'm using VS2012.
I made a simple service that I ran yesterday and it worked fine.
But now I'm doing it all again, just to review it, and for my surprise it doesn't work.
Don't know why the machine is actively refusing it 127...:6414.
The service is being run locally, in the same machine, and VS 2012 is being run as Administrator.
This is the complete the error:
"There was an error downloading 'http://localhost:6414/HostDevServer/HelloWorldService.svc'. Unable to connect to the remote server. No connection could be made because the target machine actively refused it 127...:6414"
I tried to make an inbound rule in the firewall, didn't work.
Tried deactivating Microsoft Security Essentials, didn't work.
Tried doing it all in other machine, the same error.
Tried changing the port number, didn't work.
I googled it and what I found wasn't for me.
The service is very simple, the ServiceModel definition in the Web.Config is this:
<system.serviceModel>
<serviceHostingEnvironment >
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./HostDevServer/HelloWorldService.svc"
service="MyWCFServices.HelloWorldService"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The service is made with a console application, is being hosted in a new web site that uses IIS Express, all in the same solution.
The property pages for the HostDevServer is:
Whe I run it the WCF Test Client throws the error:
What could it be?
I'd downloaded your project and run it in my machine with no problems. If your problem happens always, it means that your machine has no services listening on the specified port, or there is a firewall stopping you. Try turning of the firewall.
Did you try to debug your web service project only? If so, tell me if you can access to the following URL: http://localhost:PORT_NUMBER/HostDevServer/HelloWorldService.svc, where PORT_NUMBER is the port that you configure for the server in your solution. Try not to use port 80, It's generally used on other applications. Maybe your service isn't starting because of a problem at compile time, so you can try deleting all .pdb files from your bin directory.
Please, try to modify your web.config. Replace your system.serviceModel tag with the following:
<system.serviceModel>
<serviceHostingEnvironment >
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./HostDevServer/HelloWorldService.svc"
service="MyWCFServices.HelloWorldService"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyWCFServices.HelloWorldService" behaviorConfiguration="metadataBehavior">
<endpoint
address="" binding="basicHttpBinding" contract="MyWCFServices.IHelloWorldService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
In VS2012, Open your "HostDevServer" -> Properties Window (F4) and check the port used at Developer Web Server.URL (http://localhost:<Port Number>), then make sure that Property Pages (Shift+F4).Start Options... .Start URL: is On and set to
http://localhost:<Port Number>/HostDevServer/HelloWorldService.svc

There was no end point listening for WCF AuthenticationService

I am trying to authenticate my user logging from windows phone 7 using
AuthenticationService WCF which is hosted in IIS 7.
I tried it without SSL and is working fine. But I want to convert it to
https.
The error I am getting is when I hit the call to this WCF from my WP7 emulator
is :
"EndpointNotFoundException"
However my web.config has the following details:
<system.serviceModel>
<services>
<service name="System.Web.ApplicationServices.AuthenticationService"
behaviorConfiguration="AuthenticationServiceTypeBehaviors">
<endpoint contract="System.Web.ApplicationServices.AuthenticationService"
binding="basicHttpBinding"
bindingConfiguration="userHttps" address="https://localhost:700/AuthenticationService.svc"
bindingNamespace="http://asp.net/ApplicationServices/v200"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="userHttps">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AuthenticationServiceTypeBehaviors" >
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
USING: AspNetSqlMembershipProvider and I am avoiding those details to make the point.
In my IIS 7, I have created an App pool and associated a self signed
certificate to the hosted WCF and in the SSL Settings options to "Require SSL
- selected" and "Ignore client certificates- checked"
I am able to browse to https://localhost:700/AuthenticationService.svc.
I was able to add this as a Service Reference in my phone, but when I call the
login method it is showing the error.
I have specified the end-point address and even then it is showing error.
Can anyone explain me how to debug this to get more details or any pointers to
solve "Using Authentication Service WCF via SSL"
EDIT 1 I tried using IP addresses and the svc URL when I tried accessing
the service through browser
svcutil.exe https://mcname.domain.local:700/AuthenticationService.svc?wsdl
EDIT 2 Tried disabling antivirus and firewalls and still no luck.
As per #Rajesh's comments, I installed the certificate in phone and it started working.
I tried all options of exporting .CER, .PFX and .P7B format and only P7B format worked for me to get it installed in phone.
The part of web.config file for enabling AuthenticationService WCF with SSL is
<services>
<service behaviorConfiguration="AppServiceBehaviors" name="System.Web.ApplicationServices.AuthenticationService">
<endpoint binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"
bindingNamespace="http://asp.net/ApplicationServices/v200" contract="System.Web.ApplicationServices.AuthenticationService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AppServiceBehaviors">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" requireSSL="true"/>
Steps followed to make it work: http://blogs.msdn.com/b/davidhardin/archive/2010/12/30/wp7-and-self-signed-ssl-certificates.aspx
The host name must be resolvable by the http agent via DNS, WINS,
hosts file, etc.
The SSL certificate must be known by a name that matches the host
name.
The trusted root certificate must be installed with the http
agent, i.e. on the phone.
Installing the certificate on to the WP7 emulator phone was the trickiest part. As mentioned earlier the P7B file was hosted on the IIS and URL was accessed via emulator browser which helped me to install the certificate on phone (Sorry! I forgot the reference link).
After the installation, the endpoint issue disappeared and it started to work. As this is not a permanent solution (because everytime emulator is closed the CERT needs to be reinstalled), I am working on http://wp7certinstaller.codeplex.com/ code to make it work when it is hosted in IIS for testing purposes.
Thanks #Rajesh for your help.

Host WCF service in console Application

I have around 15-20 services - each service has its own contract and implementation file. I want to host all these service in a console app so that it will be easier to debug during development.
Project structure
Services - Solution
ServiceContracts - Project
Implementation - Project
ServiceHost - Windows Service project -- Already inplace and working fine..
ServiceConsoleHost - Project - Currently working on it.
I have an app.config file in the ServiceConsoleHost project here the sample text from config file...
<service name="TestpricingService" behaviorConfiguration="HostBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/testService/pricingService"/>
</baseAddresses>
</host>
<!-- use base address provided by host -->
<endpoint address="net.tcp://localhost:820/testService/pricingService"
binding="netTcpBinding"
bindingConfiguration="HostBinding"
contract="Test.Services.Contracts.IpricingService" />
<!-- the mex endpoint is exposed at http://localhost:8000/testService/purchasing/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="HostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name="PooledHostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<ObjectPoolingServiceBehavior minPoolSize="0" maxPoolSize="5" idleTimeOut="30000"/>
</behavior>
</serviceBehaviors>
</behaviors>
Thanks in advance...
You are probably looking for self-hosted services. See MSDN Reference on self-hosting using ServiceHost.
Also take a look at enumerating WCF configuration bindings. Here is an SO post which describes enumerating WCF service and endpoint bindings.
as everyone mentioned you need 15 ServiceHosts to host 15 services. However they are not blocking. If you notice the MSDN code just sits waiting for a keypress whilst the service is running. This means all the service code is running on separate threads. So creating and hosting 15 services is not an issue. You dont need a "loop" as that is already handled once you do ServiceHost.Open().

Configuring WCF Security (wsHttpBinding)

I have two websites hosted on the same IIS server. SiteA contains WCF services that need to be accessed by SiteB, as well as anything else that is authenticated on the domain.
The service is configured with a wsHttpBinding and thus I believe uses Windows security by default. Right now I can call the services from a console app running on my local machine, as well as from a web application running in the default Visual Studio web server, so I am taking that the authentication is working.
However, when SiteB tries to access the services, it fails with this error:
The caller was not authenticated by the service.
SiteB runs on the same machine than SiteA so I don't understand why it could not be authenticated. SiteB uses Forms Authentication and I mapped Anonymous access to a domain user.
Here are the config bits:
SiteA (service):
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="wcfServiceBehaviour" name="MyService">
<endpoint address="" binding="wsHttpBinding" contract="IServiceContract" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
SiteB (client):
<system.serviceModel>
<client>
<endpoint address="http://xxxxx/Services/xxService.svc"
binding="wsHttpBinding"
contract="IServiceContract" />
</client>
</system.serviceModel>
You are correct - wsHttpBinding configured in WCF will use Windows Authentication by default.
There is a suggestion here - WCF - changing endpoint address results in securityexception - that the Identity block will not work with Windows Authentication - try removing it.
When SiteB impersonates another user, does your code specify the impersonation level?
My guess is that your are not specifying a high enough level of impersonation. (Delegation is the highest, allowing SiteB to pass the permissions to a different service).
I suspect that fixing up the SiteB impersonation code will be enough to solve the problem.
If not, try passing the allowable impersonation level to the server:
<system.serviceModel>
<client>
<endpoint address="http://xxxxx/Services/xxService.svc"
binding="wsHttpBinding"
contract="IServiceContract"
behaviorConfiguration = "ImpersonationBehavior" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel = "Delegation" /> <!-- The highest level -->
</clientCredentials>
</behavior>
<endpointBehaviors>
</behaviors>
</system.serviceModel>
If you're using a self hosted site like me, the way to avoid this problem (as described above) is to stipulate on both the host and client side that the wsHttpBinding security mode = NONE.
When creating the binding, both on the client and the host, you can use this code:
Dim binding as System.ServiceModel.WSHttpBinding
binding= New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None)
or
System.ServiceModel.WSHttpBinding binding
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);

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.