37

I am developing a simple wcf service for test. When I test this service with my local IIS 7.5, then it works properly. But when I host it in web IIS, I receive this error:

The type 'WcfServiceLibrary1.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

And my ServiceHost is:

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary1.Service1" %>

Please help me resolve this problem

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
hamed aj
  • 1,960
  • 8
  • 27
  • 38
  • i think i have problem with assembly – hamed aj Mar 12 '11 at 16:59
  • 6
    **Which files** did you deploy to your IIS web server?? You need: a virtual directory with the *.svc file inside it, and a `bin` directory beneath with this with DLL containing your WCF service – marc_s Mar 12 '11 at 17:06
  • yes, i create a directory in my host space and copy all my project (WcfServiceLibrary1) to my directory (for test). but my problem not solved!!! in my project exist a .svc file and service worked with local iis properly – hamed aj Mar 12 '11 at 17:13

19 Answers19

41

Because I couldn't find this suggested in any of the questions I looked through for this, adding my case here:

I had this problem when I manually changed the namespace in the file MyService.svc.cs, and did not change the Service name in the corresponding file MyService.svc - turned out that it needed to be Service="namespace.classname".

Jac
  • 1,084
  • 8
  • 16
  • 4
    This got me too, while putting together my first 'Hello World' WCF service. If you change the namespace in the code behind, don't forget to right click on the .svc, choose 'show markup' and as Jac says, edit the namespace there too. – Ted Jul 22 '13 at 14:15
  • 3
    This namespace fix also applies if you are injecting an external WCF Service Application into an ASP.NET web application like below. Make sure that the namespace is specified in the serviceActivations: ` ` – CrazyPyro Jan 21 '14 at 21:57
  • And if you're doing it that way, you'll probably also need to allow [AspNetCompatibilityRequirementsMode](http://stackoverflow.com/a/11904369/268066) – CrazyPyro Jan 21 '14 at 22:01
  • I found this same problem on my project. I initially added a service, added it to a folder, and then added another service in the folder. Copy-n-paste the original service def in the web config for the new service, and then the new would not work: interfaces, .cs and config al match except for names. When I finally checked the markup for the svc, the namespace in the Service tag did not match the webconfig. I fixed that, and it works. – callisto May 03 '14 at 19:01
  • I also got this error because the interface name was different to the service name. I had the service name 'MyLog' and changed it to 'MyLogService' without also changing the interface name to 'IMyLogService' – quilkin Feb 24 '15 at 17:48
21

Try using the assembly qualified type name.

This is [Fully Qualified Type Name], [Assembly]

Where [Fully Qualified Type Name] is, in the most common cases YourNamespace.YourType

And [Assembly] is, in the most common cases YourAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

It gets more complicated than this (generic types, nested types etc) - but unlikely to be so in your case.

If your application is using the default build options, then I'm going to hazard a guess that the directive should be something like this:

<%@ ServiceHost Language="C#" Debug="true" 
   Service="WcfServiceLibrary1.Service1, 
            WcfServiceLibrary1, 
            Version=1.0.0.0, 
            Culture=neutral, 
            PublicKeyToken=null" %>

Although you'll probably want to get rid of the newlines there.

Also, make sure your dll has actually been deployed

Andras Zoltan
  • 41,961
  • 13
  • 104
  • 160
  • 2
    *.dll file (include my service) has been deployed in Bin folder – hamed aj Mar 12 '11 at 17:14
  • please give me a example ServiceHost with fully qualified type name – hamed aj Mar 12 '11 at 17:15
  • thanks for your answer. im using assembly qualified type name, but my problem not solving with this approach – hamed aj Mar 13 '11 at 07:43
  • The extra precision in specifying the assembly version/etc isn't (always) needed. You may be able to get away with: Service="WcfServiceLibrary1.Service1, WcfServiceLibrary1" – Frederik May 01 '13 at 12:01
8

I had the same issue only when publishing my service but it worked locally.

It turned out to be that the service was referencing a DLL that wasn't being deployed. It's a super special case because it was a system dll (System.Web.Helpers) and thus the project didn't even have a reference to it and thus the "Copy Local" wasn't set to true.

mike kozelsky
  • 231
  • 3
  • 6
  • 1
    Seems like a ridiculous thing to check but my DLL was missing too. – Aaron D May 15 '14 at 18:03
  • I had a Microsoft.Identity assembly that was not set to Copy Local, and it produced just this error when deployed to production, but not when running locally. Incredibly annoying, but true. – David Keaveny May 23 '14 at 02:00
  • A dll referenced by my data service was missing from the bin\ folder and that generated the error. Added the missing dll, service worked. – Ryan Rodemoyer Apr 23 '15 at 18:54
8

IIS defaults to expecting to see the svc file in the virtual directory, and the binaries inside a bin folder (as marc_s commented).

However, the default build configuration for WCF Library projects is to build inside a bin/Debug folder (or bin/Release). You can change the Output Path to 'bin/' on the project properties Build tab.

Changing this resolved this error for me today.

Nij
  • 2,028
  • 2
  • 22
  • 27
  • The default output path in my case for a WCF project was bin\ I received the issue when I changed the output path to bin\Debug. Worked fine when I changed it back to to bin\ – Matt Fricker Oct 09 '18 at 22:01
4

I had this same problem after I deployed a working service to a new location (new site) in IIS. In inetmgr under the Default Website tree, I hadn't right-clicked the new site and selected Convert to Application - all working now!

Tom Tom
  • 423
  • 4
  • 9
4

Finally my problem solved.

I removed the service directory in my host and created a new virtual directory in the host space. Then I copied my service in new directory where I created it.

Now I can browse the .svc file for service and my client will consume the service.

I don't understand why this problem occurred! I am a little confused!

Jeff B
  • 8,572
  • 17
  • 61
  • 140
hamed aj
  • 1,960
  • 8
  • 27
  • 38
  • 1
    I had added mine as a plain directory and needed to convert it to an Application. – tsilb Aug 13 '13 at 15:51
  • the above comment is what I had to do to: in my localhost, the dir was an application or virtual directory, and when I deployed to the www, I had just ftp'd stuff up there. – pdschuller Jun 24 '14 at 17:50
3

The answer marked as answer is very difficult to understand. In fact, although it led me to solve my similar problem, I don't know if that's because I accurately understand what the writer was meaning.

I was finding if I pointed an IIS application on my development machine to the actual project directory in which resides the web.config, MyService.svc, and bin folders necessary for the WCF Service Application it just wouldn't work, and was throwing this error. This is despite quadruple checking every setting and ensuring that things were equivalent to other simple, working WCF Applications.

Ultimately, I solved the problem by publishing to a different directory rather than depending on the project files and directory themselves.

Perhaps it was because the files were open in Visual Studio as I was trying to run the WCF application through IIS? I don't know, but the Visual Studio provided localhost:59871/... was working. I don't know if that instance is using the project files or a temporary published version.

argyle
  • 1,319
  • 2
  • 14
  • 28
2

Check whether namespace and class written in "Service" of "SeviceHost" is correct .It should be Service="namespace.classname" .

teo van kot
  • 12,350
  • 10
  • 38
  • 70
  • This fixed it for me. The conversion code that runs after clicking 'convert to web application project" gave (the former website project) a new namespace which was NOT prepended to the service classname in the svc file. – Tom McDonald Oct 17 '16 at 20:20
1

Another reason for this issue is often when a wcf service is moved from one directory to another, and the svc file has not been updated... easiest solution is to double check your .svc file and make sure the service definition is defined correctly.

Sean Haddy
  • 1,630
  • 1
  • 16
  • 25
1

As I can't up vote @jeromeyers answer at the moment, I want to add that this is the solution that I found for this issue.

Someone had copied and pasted a svc file and associated contract and code files to a new project, but they had not updated the namespaces and class names everywhere. Very frustrating tracking this down as it started with this error :

" name was started with an invalid character. Error processing resource 'file:///C:/...

<% @ServiceHost "

when trying to right click on the .svc file and doing "View in browser".

Mark P
  • 191
  • 1
  • 2
1

Even though this is slightly different than the question (not web iis): I got here through search because I was getting this error trying to Debug my service -- if you have multiple services inside a single solution, this error will occur if the solution in question is not built yet, and therefore the DLL not created when you try to access it. So to anyone out there make sure if running locally that the entire solution is built!

Robert Noack
  • 1,286
  • 14
  • 22
1

had this problem running a test project that was embedded in my solution.

I had to view in browser, then copy that link to a new service reference (delete the old one) then paste it in rather than using the discover utility button in the service reference.

DirtyHowi
  • 111
  • 1
  • 5
1

Strange as well, after looking and trying others suggestions, i was still getting the error saying the: The type ', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Sure we all get large project with a lot of DLLs. Turned out some of the older components in my solution were targeting .Net 4.5, and newer dll were build with 4.5.1. When the 4.5 dlls referenced the 4.5.1 dlls .... Not sure why i was the happy little guinea pig to be the first on my team to find this. While the fix was obvious and easy enough, just all the dlls to target the same .Net runtime.

Just wish Visual Studio would notice DLLs within the same solution should all target the same .Net runtime and generate a warning/error when building especially with we have a solution and a project reference and the runtimes don't match...

Dano
  • 112
  • 7
  • In my case reason was similar. It was mixed with lack of reference in ServiceHost to InterfaceLib, that was implemented by the service specified in .svc file – krzyski Apr 13 '17 at 09:45
1

Be sure your compiled dlls are moved to service(IIS directory) directory.

For example, sometimes Jenkins doesn't move them automatically.

0

I had the same issue when i uploaded my working localhost service to a new location on host. I create a new Virtual Directory and published my Service to it via Visual Studio(FTP). Problem Solved.

Armin
  • 599
  • 2
  • 8
  • 19
0

It happend the same to me and the solution was creating a forder named "bin" and place the dll inside of it. Then, refresh the website on IIS and that's all

0

I had this problem too, and what did the magic for me was to restart the IIS. This is a very weird error.

ParPar
  • 7,355
  • 7
  • 43
  • 56
0

enter image description hereenter image description here

First time hosting WCF Service Application, in IIS ? Many have solved their problems one way or the other. However if everything is your solution is correct and your error is about host your app in IIS, then ensure your physical path in IIS when you add your website is pointed to the "bin" directory of your solution as seen below in the screen shots.

Julius Depulla
  • 1,493
  • 1
  • 12
  • 27
0

Please look at https://msdn.microsoft.com/en-us/library/ms733766(v=vs.100).aspx

You need to do 2 things to be able to Host the Service on IIS, or even on Visual Studio's itergrated IIS_EXPRESS.

1) Update the Web.Config to include ServiceActivations

change:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

to

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
  <serviceActivations>
    <add service="API.Service1" relativeAddress="Service1.svc"/>
 </serviceActivations>
</serviceHostingEnvironment>

2) You need to create a directory called App_Code in the root directory. You now need to move the Service (ex: Service1.svc) from the root directory into the App_Code directory. So you will have App_Code\Service1.svc

If you browse the Service http://localhost:63309/Service1.svc it should work.