Is it possible to use netTcpBinding with the VS 2008 development server? - wcf

Is it possible to have a WCF service configuration like this:
<service behaviorConfiguration="WcfService1.Service1Behavior"
name="WcfService1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfService1.IService1">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/netTcpService" />
</baseAddresses>
</host>
</service>
And have it hosted on the ASP.NET development server that comes with Visual Studio 2008, or do I necessarily have to host the service in IIS 7 or self-host it in a managed application/Windows service?
Thank you for your insights!

IIS6 and the built-in Cassini web server both support only http, sorry.
You'll have to either self-host your service in e.g. a console app, or host it in IIS7 in order to use NetTCP.
VS2008 SP1 also comes with a WCF Test Host app that can be used for those purposes, and it supports NetTCP and all other protocols as well.
It's called WcfSvcHost.exe and should be found in your C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE directory. You can specify a DLL containing your service implementation and a config file for it, and it'll load your service and host it for you.
MSDN documentation for the WcfSvcHost is here:
http://msdn.microsoft.com/en-us/library/bb552363.aspx
Here's what it'll look like in your environment:
and here's the WcfTestClient.exe connected to that hosted service - note the netTcp endpoint:
To set it up in Visual Studio, use the WCF service library project's "Properties" tab and pick to launch WcfSvcHost.exe as the external program and supply the correct command-line arguments like this:
Now if you press F5 to run the class library containing your WCF service, it'll launch the test host and host your service library in there, ready to be tested.
Marc

Related

Wcf bindings difference while hosting on windows azure

I have wcf service application which i host on IIS and runs very well.
now i need to transfer the services to windows azure where i host them into web role.
i am not sure but i have heard that there are different bindings for windows azure
example:
azure has different bindings equivalent to basicHttp,WebHttp.
can i know what exactly i need to do to achieve the same.
here is my current service configuration
<service behaviorConfiguration="mybehavior" name="***">
<endpoint address="mobile" behaviorConfiguration="web" binding="webHttpBinding"
contract="*" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:81/Mobile.svc" />
</baseAddresses>
</host>
</service>
what change does this need
Thanks
You can achieve your goal with web.config transofmrations (and here). The issue with Azure is that there is no localhost, nor 127.0.0.1 there (well, there might be, but nothing is being routed to that local loop address). All you have to do is to change the baseAddress.
In order to change the baseAddress you may do any of the following:
use web.config transofmrations and in your web.Release.config put your azure domain name in the base address (http://yourapp.cloudapp.net/, or your custom domain if you are using one)
programatically bind the wcf service using the DIP of the role instance (check this and that questions for more information)

How to use msmq between WCF Router and WCF Service hosted in a Windows Service

In my current system I have a router service and over a dozen (about half use msmq, rest use tcp) WCF services hosted via IIS. I've been tasked with moving all services except for the router to a windows service. This has been accomplished using the same configurations that were present using the IIS web.config file. Here is a snippet of the previous configs (public queue for service: myservices/wcfservice):
<!--Router Service web.config-->
<client>
<endpoint address="net.msmq://localhost/MyServices/WCFService.svc" binding="netMsmqBinding" contract="*" name="IWCFService_Msmq" />
</client>
<!--Services web.config-->
<service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
<endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
contract="IWCFService" />
<host>
<baseAddresses>
<add baseAddress="net.msmq://localhost/MyServices/WCFService" />
</baseAddresses>
</host>
</service>
I'm confused as to why this works, as the service has a net.tcp binding and the router has msmq, and when I asked around, I was told it was "magic." I tried to do the same thing with my setup (router to windows service) using a similar configuration but get an error message:
<!--Router Service web.config-->
<client>
<endpoint address="net.msmq://localhost/MyServices/WCFService" binding="netMsmqBinding" contract="*" name="IWCFService_Msmq" />
</client>
<!--One "other" Services hosted in Windows Service app.config-->
<service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
<endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
contract="IWCFService" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/MyServices/WCFService" />
</baseAddresses>
</host>
</service>
This has worked fine with all my services that are just using tcp, but when I try this with msmq and attempt to start the windows service, I get the following error in the Event Viewer:
Service cannot be started. System.InvalidOperationException: Could not find a base address that matches scheme net.msmq for the endpoint with binding NetMsmqBinding. Registered base address schemes are [net.tcp].
I'm new to msmq, so any help with be appreciated. Thanks!
Updated:
I've updated the base address in the service app.config to match the address that is in the router web.config. I tried this previously and it didn't work. I later found out it was because I didn't make the msmq itself a "Transactional Queue" (which was needed for our setup). Once this was done, everything worked out!
<!--One "other" Services hosted in Windows Service app.config-->
<service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
<endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
contract="IWCFService" />
<host>
<baseAddresses>
<add baseAddress="net.msmq://localhost/MyServices/WCFService" />
</baseAddresses>
</host>
</service>
Judging by the error message of the InvalidOperationException, it looks like "net.tcp" is the only enabled protocol in the Advanced Settings of your application hosted in IIS.
Is "net.msmq" an enabled protocol?
Open IIS Manager
Select your application
Click Advanced Settings in the Actions list
Add "net.msmq" to Behavior - Enabled Protocols
Why not give all of your MSMQ services their own config and all the tcp services their own? The issue is obviously it looks for a base address when you choose the binding to be msmq, and it can't find an msmq binding because all you've provided is a tcp base address binding. You can also of course add another base address that uses net.msmq inside the baseaddresses node.

wcf endpoint relative address

I'm just learning wcf and can't understand one very basic thing.
I'm creating a WCF service which I want to be hosted in IIS just like web application with it's own path like http://myhost/myapp/ and everything.
I'm creating the WCF service project in VS, I've got an *.svc file describing it, then I define a simple endpoint to it like that:
<endpoint address=""
binding="basicHttpBinding"
contract="wcf_service_auth.IPshService" />
Then I publish this service like an IIS web application to a virtual directory, let's assume it's name psh_pub, so I can access the service via url http://localhost/psh_pub/pshservice.svc/. It shows me WCF greetings page and gives me a link to WSDL, which gives me correct wsdl description.
That's ok.
The next step - I want to add a MEX endpoint. I add to config:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
That's ok too, the endpoint is accessible at address http://localhost/psh_pub/pshservice.svc/mex and WcfTestClient.exe gives me correct config from that url.
Here the problem comes.
I have a WCF service working under IIS and I want to add one more endpoint to it. For example let it be a net.tcp endpoint. The IIS is configured by default to accept net.tcp connections at port 808 and I'm adding net.tcp protocol to properties of my web app, and I want to add an endpoint to my service like that:
<endpoint address=""
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
and now I assume that my service should be accessible via the url net.tcp://localhost:808/psh_pub/pshservice.svc. But it's not. And every "how-to" and manual on the web tells that I should specify full address in the config file like that:
<endpoint address="net.tcp://localhost:808/psh_pub/pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
And if I do so, it works. But if host the service in another virtual directory, I'll need to change the config. If I host it on the other server, I'll need to change config. If I host it on multiple servers, I'll have to maintain as many configs as servers I have.
So the main questions is:
Is there any way in WCF to specify a net.tcp (or https) endpoint of a IIS-hosted WCF service without specifying absolute url for it?
You should be able to define a base address for your net.tcp service endpoints:
<service name="YourServiceName">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/psh_pub/" />
</baseAddresses>
</host>
Then you should be able to use relative addresses in your actual endpoints:
<endpoint name="Tcp01"
address="pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
</service>
WCF file-less activation (.Net 4.0) will let you register under a relative virtual path using the relativeAddress attribute:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="relative-virtual-path/yourservice.svc"
service="YourServiceImpl" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
relative to the base address of the Web application
This link talks about it: http://msdn.microsoft.com/en-us/library/ee354381.aspx

Configure WCF host for windows integrated security

I have WCF service hosted on IIS7.5 running as anonymous - authentication, Please let me know the configuration/steps to run on windows integrated security. Thanks
Well the nice thing about NetTcpBinding is that it is secured using Transport security, Windows authentication by default. So all you need to do is use it. Your server binding would look something like this:
<service name="YourServiceNameHere">
<host>
<baseAddresses>
<add baseAddress="net.tcp://machineName/VirtualDirectory/"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="netTcpBinding"
contract="YourServiceContractHere" />
</service>
Here is an MSDN article that goes more in depth. In IIS, you need to enable net.tcp, and enable Windows authentication.

How to configure the IIS to support WCF service?

I wrote WCF service ( web service ).
I never work with the IIS - and i dont know if i need to change \ config something in the IIS to work with my service.
Someone can help me ?
Thanks
P.S: IIS version is 7.5
Hosting a service on an IIS Web server is very similar to hosting a traditional Web service (with an .asmx file extension).
Services hosted in IIS require the creation of a file with an .svc file extension. This is done for you automatically if you use the Visual Studio 2008/2010 WCF Service template. The Service.svc file is an XML-based file that must include an #ServiceHost directive.
<% #ServiceHost Language="C#" Service="EmployeeService" %>
in the web config you can leave the address attribute blank.
<services>
<service name="EmployeeService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IEmployeeService" />
<endpoint binding="wsHttpBinding" name="wsHttpBinding" contract="IEmployeeService" />
<endpoint binding="basicHttpBinding" name="basicHttpBinding" contract="IEmployeeService" />
</service>
</services>
For more info take a look at: http://msdn.microsoft.com/en-us/library/ms733766.aspx