How to configure the IIS to support WCF service? - wcf

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

Related

"There was no endpoint listening at" issue with a IIS Hosted WCF Service consuming another web service

I have created a WCF service which is hosted in IIS and that tries to call another web service (3rd party) to return some data. When trying to connect the service fails with the following error:
There was no endpoint listening at https://xxx (3rd party ws) that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
And this is while, my service is up (i know from my echo method) and it works successfully if it is self hosted.
I have the whole and sections copied to the model of web.config exactly as it is for the self hosting test but something still is missing.
I have been through other similar problems reported but mine is little bit specific in that the service is kind-of hosting another one and that one is causing the issue.
I can try to exlain better with a real example:
There is a simple web service here: http://www.dneonline.com/calculator.asmx which I want to wrap inside our library and provide access to via an IIS hosted WCF.
So, a class library is created (Calculator project) to with one method, add to take two int arguments and use them to call the web service add method. The webservice is referenced as a Service Reference inside the library and is being addressed inside from within the config library app.config file like below:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculatorSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
</system.serviceModel>
</configuration>
Then there is a WCF class library (CalcService project) which uses the first class library to enable http endpoints. Again, the app.config file includes endpoints both as for the service itself and as a client of the class library. The app.config file looks almost like this:
<configuration>
<system.serviceModel>
<services>
<service name="CalcService.Calc">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/CalcService/Calc/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="CalcService.ICalc">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<!-- Client endpoint, i.e. to be able to use the calculator.asmx service addressed in the class library -->
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I am able to test the whole thing via a console application that makes a call to the WCF service and receives an answer. The console application config file has only one client endpoint to the WCF like below:
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/CalcService/Calc/"
binding="basicHttpBinding" contract="Calculator.ICalc" name="BasicHttpBinding_ICalc" />
</client>
</system.serviceModel>
</configuration>
My question is now how I can host the WCF service inside IIS? I have tried different ways but neither one worked. My current IIS project (which doen't work) looks like this:
1-Has project references to both prevoius projects (Class Library and WCF Service) so two dll files are being added to the references:
CalcService.dll
Calculator.dll
2-Has a CalcService.svc file which creates a ServiceHost toward the CalcService:
<%# ServiceHost Language="C#" Debug="true" Service="CalcService.Calc"%>
3-Has a web.config with cliend endpoint to calculator.asmx:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculatorSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
<!-- some other settings -->
</system.serviceModel>
Now, when tested with a simple client to make a call to the calculator add method it fails with the following error:
There was no endpoint listening at http://www.dneonline.com/calculator.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I don't know which message the endpoint is expecting, I could just assumed it has to be Service.CalculatorSoap as it worked before from the console application.
On the other hand, what confuses me is that a self hosted WCF also works (via http://localhost:8733/Design_Time_Addresses/CalcService/Calc/ from the config file in the WCF class library project).
I don't know what is missing here, is it something from the IIS configuration or permissions?
Or someting else like the windows firewall setting like explained in this post:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/bec3ab7a-310e-415f-b538-6d5681e5e53c/there-was-no-endpoint-listening-at?forum=wcf
Just note that since I am using a company computer, I'm not able to shut down the firewall. I can just turn on/off some of the rules.
I hope it is clear now what we are after.
We tested the solution on a cloud based machine and it worked fine. In the end it looked to be some firewall rules blocking the IIS outgoing calls and nothing was wrong in the configuration files or in the code.

Unable to configure WCF service for net.tcp in IIS hosting multiple sites

Trying to set up second web site in IIS 7, most/all of the mirrored services function except ones configured for net.tcp. Trying to access the .svc url, I receive the following error:
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
IIS binding configuration:
Advanced Settings:
Trying to follow answers found on Stack Overflow, none seem to work.
Content of the service's web.config:
<system.serviceModel>
<services>
<service name="ServiceName">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
name="basic" contract="ServiceName.IService" />
<endpoint address="nettcp" binding="netTcpBinding" bindingConfiguration=""
name="netTCP" contract="ServiceName.IService" />
<host>
<baseAddresses>
<add baseAddress="http://staging.localhost/ServiceName" />
<add baseAddress="net.tcp://localhost:8033/ServiceName" />
</baseAddresses>
</host>
</service>
</services>
Is there a trick to the net.tcp bindings? What is correct configuration needed in the web.config?
Thanks!
A screenshot is worth a 1,000 words sometimes. In IIS manager, right-click on the application "ServiceName" and select Manage Application->Advanced Settings. In the advanced settings dialog box, check to see if you've added net.tcp to the Enabled Protocols:

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

Steps to host a WCF service in IIS5.1(XP)

I have developed a sample WCF service. I would like to know the steps to host this in IIS 5.1(XP)
1) You need a IIS virtual directory --> create it using IIS Manager
2) You need a *.svc file which references your service - it's a text file which must reside inside your virtual directory just created, and it would be something like:
<% #ServiceHost Service="YourNameSpace.YourServiceClass"
Language="C#" Debug="False" %>
That works if your WCF service class is in an assembly deployed to the "bin" directory below your virtual directory.
If you happen to have your actual service code in a "code-behind" file inside your "App_Code" directory (which I would not recommend), then you'd need this contents in your *.svc file:
<% #ServiceHost Service="YourServiceClass"
CodeBehind="~/App_Code/YourServiceClass.cs"
Language="C#" Debug="False" %>
3) You need your config in web.config - you need at least the <service> tag plus possibly more depending on your needs:
<system.serviceModel>
<services>
<service name="YourNameSpace.YourServiceClass"
behaviorConfiguration="MetadaTaEnabled">
<endpoint address=""
binding="wsHttpBinding"
contract="YourNameSpace.IYourService" />
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadaTaEnabled">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
Here, you need to decide what binding (protocol) to use.
If you do all this, and everything was successful, you should be able to browse to your virtual directory URL with IE (http://yourserver/virtualdirectory/YourService.svc) and see the "landing page" of your service.
Marc
Have a look at this article on MSDN. It has information about hosting WCF services in all versions of IIS.