注意:这个问题比谷歌搜索现有答案需要更多的努力。我已经做到了。我认为有人需要非常友好地在他们自己的托管服务上测试项目,并找出可能导致此错误的原因。
我创建了一个在开发PC和内部IIS服务器上使用时工作正常的WCF服务。我的问题是,当部署在托管服务(webhoster)上时,同样的WCF服务不起作用。
我知道我可以在这里和其他讨论类似问题的网站上找到许多相关问题,但我无法让它与所有这些信息一起工作。我输了。也许我只是忽略了一些愚蠢/简单的事情,但我现在处于一种我根本看不到它的状态。
我创建了一个非常简单的测试项目,如果需要,可以在下面下载。此存档文件还包含一个Publish文件夹,其中包含托管内容的确切内容。
https://preview.cubbyusercontent.com/pl/TestService.7z/_785cfac455fe44b0820c1ed39cf7573b
我在网站托管服务上托管此WCF服务,因此我无法直接访问IIS。该文件夹设置为应用程序。
再次说明:WCF服务在本地(在我的开发机器上)运行良好,并且在我们自己的IIS上部署时也是如此。部署在外部托管服务上时,我只有这个问题!
注意:这个例子中的语言是VB,但我也使用C#。所以,如果您提供任何语言的示例,那就没关系。
目前确切的错误消息如下:
Server Error in '/' Application.
The type 'TestService.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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The type 'TestService.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.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The type 'TestService.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.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +59206
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1434
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
[ServiceActivationException: The service '/xxxxxx/v1/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'TestService.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..]
System.Runtime.AsyncResult.End(IAsyncResult result) +494824
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +348350
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9549981
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18449
我非常有帮助的托管服务确实实现了以下链接中提到的建议:
http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-using-aspnet-35-and-aspnet-45 http://gyorgybalassy.wordpress.com/2012/09/24/publishing-a-wcf-service-on-iis8/
不幸的是,这些补充并没有解决问题。
注意:请不要参考一般文档而不解释为什么我的服务不能在托管服务中工作。
更新1: 根据Maxwell的建议,我使用以下Service2.svc文件(1个文件中的代码,不使用DLL)进行了单独的测试:
<%@ ServiceHost Language="C#" Debug="true" Service="TestService.Service2" %>
using System;
using System.ServiceModel;
namespace TestService
{
[ServiceContract]
public interface IService2
{
[OperationContract]
string GetData(int value);
}
public class Service2 : IService2
{
public string GetData(int value)
{
return "You entered: " + value;
}
}
}
web.config文件:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<system.web>
<customErrors mode="Off"/>
<compilation strict="false" explicit="true" targetFramework="4.0"/>
<httpRuntime/>
</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">
<baseAddressPrefixFilters>
<add prefix="http://www.YourDomainName.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</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>
我现在收到以下错误:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 21: <add binding="basicHttpsBinding" scheme="https"/>
Line 22: </protocolMapping>
Line 23: <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
Line 24: <baseAddressPrefixFilters>
Line 25: <add prefix="http://www.YourDomainName.com"/>
Source File: \\192.168.0.100\localuser\plusserie\taskmanageronline\bpmlicense\v1\web.config Line: 23
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18045
答案 0 :(得分:2)
很抱歉,这不是您问题的直接解决方案,但希望它有助于找到问题:
您收到的异常似乎是无法找到并加载您的服务正在实施的类型的结果(显然我认为)。查看reference code(请参阅stacktrace中的最后一个方法),在我看来,由于某种原因,IIS无法加载TestService.dll
文件。也许是权限问题,我无法说明,但这里有一些建议可以帮助您解决问题:
首先,你是否尝试在线运行服务只是一个.svc文件?如果您要发布或上传此单个.svc文件,您是否可以使用此服务?
<强> Service2.svc 强>
<%@ ServiceHost Language="C#" Debug="true" Service="TestService.Service2" %>
using System;
using System.ServiceModel;
namespace TestService
{
[ServiceContract]
public interface IService2
{
[OperationContract]
string GetData(int value);
}
public class Service2 : IService2
{
public string GetData(int value)
{
return "You entered: " + value;
}
}
}
只需浏览/path/to/Service2.svc
,看看是否有效(希望如此)。这意味着您可以在目标环境中使用WCF服务。如果没有,希望你有一个不同的例外,你可以通过。
如果可行,现在您可以测试是否可以从要发布的DLL加载类型。再次使用这个内联单个文件来测试:
<强> Test.aspx文件强>
<%@ Page language="C#" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Web" %>
<%
var serviceType = "TestService.Service1";
Type type = null;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
type = assemblies[i].GetType(serviceType, false);
if (type != null)
{
Response.Write("Found it! " + type.ToString());
break;
}
}
if (type == null)
{
Response.Write("Not found");
}
%>
有了这个,你可能会得到一个Not found
结果(如预期的那样)。此时,您可以确定您的装配是否可访问。尝试使用其他几个程序集,将服务代码编译到不同的程序集中并上传它,依此类推。上面的代码几乎取自我上面提到的参考代码。这似乎是WCF尝试做的事情,并且在找不到服务类型后失败了。
更多的故障排除建议而不是答案。我希望它有所帮助。
祝你好运!答案 1 :(得分:0)
您可以做的最简单的事情是将以下配置更改为false。 的 aspNetCompatibilityEnabled =&#34;假&#34; 强>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
否则,您可以将以下属性添加到Service类。
VB中的代码修复
Imports System.ServiceModel.Activation
Imports System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class Service1
Implements IService1
Public Sub New()
End Sub
NB:以下代码位于C#
using System.ServiceModel.Activation;
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
....
}
答案 2 :(得分:0)
看起来小房间倒塌了。你解决了问题了吗?如果没有,请确保存在TestService.Service1
类型,并检查您要部署的文件夹(在IIS中标记为应用程序的文件夹)是否具有Steve正在讨论的“.svc”文件。如果你没有,你可能需要添加一个。
以下是“service.svc”文件中应包含的内容示例。
<%@ServiceHost
language="c#"
Debug="true"
Service="Microsoft.ServiceModel.Samples.CalculatorService"%>
另请查看MSDN上的How to: Host a WCF Service in IIS文章。
答案 3 :(得分:0)
您是否可以与托管服务提供商确认已启用WCF服务激活?
http://msdn.microsoft.com/en-us/library/ms731053(v=vs.110).aspx(让他们更改相应版本的版本)
这里也是非命令行方式 - http://blogs.msdn.com/b/blambert/archive/2009/02/13/enable-iis.aspx
还可以尝试将激活添加到您的web.config文件
http://msdn.microsoft.com/en-us/library/ee816902(v=vs.110).aspx
答案 4 :(得分:0)
尽管存在模糊的错误消息,我仍设法解决了这个问题。我已将Web服务放在包含其他Web服务的父文件夹的子文件夹中。该web.config与我的WCF服务的web.config冲突。
在我将WCF服务放在根文件夹中后,WCF服务正常工作。