0

I have a WCF service that I've had running on Server 2012R2. I tried moving the service to Server 2016 and began getting the following error:

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

I literally moved the whole directory from one server to the other -- so all the code and settings are the same.

My service is configured in web.config like this:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  ...
  <services>
    <service name="MyService" behaviorConfiguration="BehaviorConfig">
       <endpoint address="" binding="webHttpBinding" behaviorConfiguration="json" contract="IMyService">
           <identity>
              <dns value="localhost" />
           </identity>
       </endpoint>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>

My myservice.svc looks like this:

<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>

Yes, the .dll containing the service is in my Bin directory.

My service definition looks like this:

[ServiceContract(Namespace="")]
public interface IMyService
{
    [OperationContract]
    [WebInvoke(Method ="POST", RequestFormat=WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    string Validate(string userId, string userText);

    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    void UserName(string userId);
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService: BaseService, IMyService
{
  //Implementation here
}

So I've read a number of posts that indicate that the .svc file is supposed to contain the type of the service -- including namespace. However, in my case there is no namespace.

The project targets .NET Framework 4.6.1.

What am I missing?

RHarris
  • 10,641
  • 13
  • 59
  • 103
  • Did you read this question, and especially links in accepted answer: https://stackoverflow.com/q/720807/5311735? First link suggests that might be a problem with dependency libraries (which might be in GAC on original server and not in directory you copied) – Evk Oct 22 '20 at 19:19
  • Just used Dependencies app to check the dll. It seemed to find all of its dependencies without problems. – RHarris Oct 22 '20 at 20:24
  • You can try debugging method used in that first link (http://www.thejoyofcode.com/WCF_The_type_provided_as_the_Service_attribute_could_not_be_found.aspx) - that is try to create your type via Activator.CreateInstance from aspx page and see if that reveals more info. – Evk Oct 22 '20 at 20:30
  • I think you need to run it as administrator – Muhammad Waqas Aziz Oct 23 '20 at 07:37

2 Answers2

0

I released WCF service on windows server 2012 R2, the file directory is as follows:

enter image description here

The files in bin directory:

enter image description here

Then I copied the entire directory to windows server 2016 and it was able to run successfully.

enter image description here

I did not encounter any problems during the process, you can refer to the files I copied to windows server 2016. You need to check if some files are missing in your directory. If it still doesn’t work, I suggest you rebuild the project in 2016 before deploying.

Ding Peng
  • 3,702
  • 1
  • 5
  • 8
0

I finally got this working. After hours of messing with this, I finally realized that on the original server, my Services sub-folder had also been made its own Web Application. IOW, I have a Web Application within a Web Application.

On the new server, I had not turned the services sub-folder into a Web Application.

RHarris
  • 10,641
  • 13
  • 59
  • 103