无法使WCF服务在第三方托管服务中工作

8 c# vb.net asp.net wcf

注意:这个问题需要更多的努力,而不仅仅是谷歌搜索现有的答案.我做到了.我认为有人需要非常友好地在他们自己的托管服务上测试项目,并找出可能导致此错误的原因.

我已经创建了一个WCF服务,在开发PC和我们的内部IIS服务器上使用时可以正常工作.我的问题是,当部署在托管服务(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
Run Code Online (Sandbox Code Playgroud)

我非常有帮助的托管服务确实实现了以下链接中提到的建议:

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 /出版-A-WCF服务-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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我现在收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

小智 0

尽管有模糊的错误消息,我还是设法解决了这个问题。我已将该 Web 服务放在包含其他 Web 服务的父文件夹的子文件夹中。该 web.config 与我的 WCF 服务的 web.config 冲突。

当我将 WCF 服务放入根文件夹后,WCF 服务就可以工作了。