Generate a svc / wsdl URL in my WCF web service - wcf

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.

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.

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

Getting Error in Endpoint While Running A WCF REST Service

I'm developing a REST service using WebHttpBinding.
Everything is perfect in my service, but while running it gives Error Endpoint not Found.
The web.config File is like this:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="Service">
<endpoint address="http://localhost:10492/Service.svc" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
In address I tried like this also:
<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
But it's still not working.
Here is a good link to get you started: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
On what address are you attempting to connect to your web service? (Have you tried navigating to the address in your web browser, and what URL did you type in?)
[EDIT]
Being that you are hosting in a web application, IIS (or whatever web server you are using) will expect that a service descriptor file exists for your service. You cannot just create a URI in the web.config, and host it in IIS without an associated 'service' file on the file-system (this is your Service1.svc file).
This is a nuance specific to hosting WCF services within Internet Information Services - it is easy to forget about this step, if you are reading tutorials designed for self-hosted scenarios.
Make sure that you have a file in your website called "Service1.svc" and it should contain something like this:
<%#ServiceHost Language="C#" Service="MyNamespace.Service1" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Here is a tutorial on hosting REST services within IIS: http://saravananarumugam.wordpress.com/2011/03/04/simple-rest-implementation-with-webhttpbinding/
Another concern that jumps out at me, is that your endpoint address you have defined ("http://localhost:10492/Service.svc") does not conform to REST conventions. I wouldnt expect this would be your problem, but it is A problem.

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.

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.