[英]WCF Service works on Server 2012 R2 but throws error on 2016
I have a WCF service that I've had running on Server 2012R2.我有一个在 Server 2012R2 上运行的 WCF 服务。 I tried moving the service to Server 2016 and began getting the following error:我尝试将服务移动到 Server 2016 并开始收到以下错误:
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.找不到在 ServiceHost 指令中作为 Service 属性值提供或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供的类型“MyService”。
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:我的服务在web.config
配置如下:
<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:我的myservice.svc
看起来像这样:
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
Yes, the .dll containing the service is in my Bin
directory.是的,包含该服务的 .dll 位于我的Bin
目录中。
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.所以我阅读了许多帖子,这些帖子表明.svc
文件应该包含服务的类型——包括命名空间。 However, in my case there is no namespace.但是,就我而言,没有命名空间。
The project targets .NET Framework 4.6.1.该项目面向 .NET Framework 4.6.1。
What am I missing?我错过了什么?
I released WCF service on windows server 2012 R2, the file directory is as follows:我在windows server 2012 R2上发布了WCF服务,文件目录如下:
The files in bin directory: bin目录下的文件:
Then I copied the entire directory to windows server 2016 and it was able to run successfully.然后我把整个目录复制到windows server 2016,就可以成功运行了。
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.我在这个过程中没有遇到任何问题,您可以参考我复制到windows server 2016的文件。您需要检查您的目录中是否缺少某些文件。 If it still doesn't work, I suggest you rebuild the project in 2016 before deploying.如果还是不行,建议你在2016年部署前重建项目。
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.经过几个小时的折腾,我终于意识到在原来的服务器上,我的 Services 子文件夹也被做成了自己的 Web 应用程序。 IOW, I have a Web Application within a Web Application. IOW,我在 Web 应用程序中有一个 Web 应用程序。
On the new server, I had not turned the services sub-folder into a Web Application.在新服务器上,我没有将 services 子文件夹转换为 Web 应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.