WCF Service. Can't host in IIS7 - c#

I have a very simple WCF service and I am trying to host it in my local IIS. I get this error all the time:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I tried to change Application Pool to Classic, but still doesn't work. I tried bunch of other web sites but no success.
Can anyone help on this please.
UPDATE 1:
I have my dll and pdb file in the bin folder and I have web.config like this:
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory" relativeAddress="./HelloWorldService.svc" service="MyWCFServices.HelloWorldService" />
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Then added a new project in IIS showing the path to the folder which contains dll.
I get error when go to this link: http://mycomputername/HelloWorldService/HelloWorldService.svc.
UPDATE 2:
In my computer .NET 3.5.1 feature was turned off. I turned it on. Then I got this error:
then I changed .net versions in Application pool to 4.0.30319. After these changes still same error:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Per the comment chain:
In IIS at the server level, ISAPI and CGI Restrictions, you'll need to enable v4.
If v4 isn't there, you'll need to install/register ASP.NET v4 with IIS:
c:\windows\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe -i

Related

VS 2022 WCF Service Application project template not working with Net TCP

I'm trying to get the simplest WCF Service Application to work with net.tcp and it's not working. Using VS2022, if I create a new project and select the WCF Service Application Template, the new project opens with a Web.config file, Service1.svc file and a IService.svc.
The Web.config looks like this,
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.serviceModel>
<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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
If I run this sample project it loads the WCF Test client and shows the service running with the BasicHttpBinding. Perfect.
If I change the binding in the config file from <add binding="basicHttpsBinding" scheme="https" /> to <add binding="wsHttpBinding" scheme="http" /> and run the project, the WCF Test Client shows the WSHttpBinding. Great! Now if I change the binding in the config file from <add binding="wsHttpBinding" scheme="http" /> to <add binding="netTcpBinding" scheme="net.tcp" /> and run the project, the WCF Test Client shows the service running with the BasicHttpBinding. THERE'S NOT EVEN A BasicHttpBinding BINDING IN THE CONFIG FILE!!!!! WHERE THE HELL IS IT GETTING THAT FROM? I've been trying for days to netTcpBinding to work and no matter I do, nothing works. I figured I'd try the simplest thing I could do, which was start with a fresh blank project and make the simplest change, and still no luck. What am I missing. I can find nearly no information on getting this work.
First you have to understand the meaning of <protocolMapping>. The configuration in shows the default protocol mapping in the machine.config file.
You need to override this default mapping at the machine level by
modifying the machine.config file. Alternatively, if you just want to
override it application-wide, you can override this section in the
application configuration file and change the mapping for the
individual protocol schemes.
More generally, the HTTP system-provided bindings such as wsHttpBinding and basicHttpBinding are configured to turn things on by
default, whereas the netTcpBinding binding turns things off by default so that you have to opt-in to get support, for example, for one of the WS-* specifications.
You need to modify the configuration file, you can see how <netTcpBinding> is configured. If you host your service on IIS, you need IIS to have net.tcp enabled.
netTcpBinding In WCF Service With IIS Hosting
nettcpbinding
default-nettcpbinding
If you need simple projects to start with, I suggest you start with wcf's beginners tutorial.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

webservice in class library Host Error

this is my first project in developing web service.
Its existing application. My project is classlibrary ..to this we added webservice.svc..
To see webservice wsdl ..what are the steps..? how to publish service in IIS.
please can anyone suggest me..
when i publish website i should publish as web deploy?
i tried to publish as webdeploy.. before that i created web site in IIS and tried to publish to hosted site in IIS ..publish succeed.. when i browse the service am getting below error, what does it mean..please help me..
provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
copied my web config file..
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I fixed my issue. Service Host service name not matching.. i tried to add test WCh service and compare .svc file..
fixed and running in IIS to..

WCF-Ajax enabled Web service. Service is not defined when deployed

I have an Ajax enabled web service within my website.
The service sits in a WebServices folder within the Root of the website, the folder also contains it's own Web.config (as the bindings for the Ajax web.config conflict the configs on another layer of my site).
I have added the web service to the scriptmanager in my master page and used JQuery to call the service within a page.
This is all working fine running locally in IIS 7 (Vista).
However when I publish the Website (locally to file system as we have to copy the files manually to our test environment) then copy the files to our test environment (running IIs 7.5 on Windows Server 2008 R2), the web service doesn't work and I get a Javascript error saying "Service is not defined".
If I browse to the service then I can view the wsdl with no problems however if I try and view service.svc/js (the same url the page is looking for) then I recieve a 404 not found error.
I've done a lot of Googling on the subject and while there are loads of suggested Web.config fixes, I have tried multiple combinations and so far nothing seems to be working.
The service it's self is very basic.
[ServiceContract(Namespace = "MyService")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyService
{
[OperationContract]
public JSONObject DoWork()
{
...Do some logic
return JSONObject;
}
}
JSONObject is a class I created that just holds some properties to be sent to the page. As I said this is all working hosted in IIS locally.
---EDIT
Here's the Web.Config that sits in the same directory as the web service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="default" />
</webHttpBinding>
</bindings>
<services>
<service name="MyWebsite.WebServices.MyService"
behaviorConfiguration="MyWebsite.WebServices.MyServiceBehavior" >
<endpoint address="" behaviorConfiguration="MyWebsite.WebServices.MyServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyWebsite.WebServices.MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyWebsite.WebServices.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyWebsite.WebServices.MyServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I also have the following section in my root web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I’ve managed to track down the issue.
It comes down to patching. The following article mentions an update to fix the issue in IIS 7.5 and Windows 7 but the patch is also applicable to Vista and Windows Server 2008.
http://support.microsoft.com/kb/2520479
There is a second option to fix the issue which involves reordering the Handlers in the IIS applicationHost.config file on the machine affected, I have tried this and it does in fact solve the issue.
The second option is described in the article above.

Failed to map path whem configuring WCF REST service for IIS 7.5

I am having an issue building and deploying WCF Rest services with IIS 7.5. If I open Visual Studio 2010 and create a new project of type "WCF Service Application" and then publish that to IIS it works fine. However, when I try to specify a WebGet Property on the operation contract from the IService.cs interface I get an error.
Interface (from IService.cs):
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet(UriTemplate = "hello/?n={name}")]
Message SayHello(string name);
}
Corresponding Method (from Service.svc):
public Message SayHello(string name) {
return Message.CreateMessage(MessageVersion.None, "*", "Hello "+name+"!");
}
I try to publish this to an IIS application I created (http://localhost/rest/) under my root site (http://localhost/) and the publish works successfully, however when I attempt to visit any page from the browser I get the following error:
Failed to map the path '/rest'.
I also tried changing the UriTemplate to [WebGet(UriTemplate = "rest/hello/?n={name}")] and I get the same error.
I am using the default configuration file from IIS:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I should also mention that I am using an application pool for .NET 4.0.
Please help as I am very puzzled by this.
Thanks in advance!
Jeffrey Kevin Pry
Since no one seemed to be interested in the question :) I figured it out on my own.
It seems that I had to do the following to get it working:
Open Command Prompt (cmd.exe)
cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ (will vary depending on setup)
Execute aspnet_regiis.exe -i
That did the trick. It is all working now. Hopefully I can save someone a few hours or so of Googling.
Thanks,
Jeffrey Kevin Pry

Default wcf service application has no endpoint defined

I just created a new WCF Service Application project in VS2010 (Premium), and it works out-of-the-box, but when I opened up the web.config file there are no endpoints present. The application works fine and I can open the address (http://localhost:50639/Service1.svc?wsdl) in a browser and I can see the contract and it all looks fine.
So my question is if the default project has uses a different approach rather then placing the information in the web.config? I can't see anything in the code either.
To show my point this is all that the web.config contains:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And still this service works and I can both connect and call the default methods (e.g. GetData())
That is not a "different" approach. It is a new approach in WCF 4.0 called simplified configuration. If you create project in .NET 4.0 you will get this simplified mode. If you create project in .NET 3.5 you will get old chatty configuration.

Categories