gpt4 book ai didi

c# - ServiceHost 只支持类服务类型

转载 作者:太空宇宙 更新时间:2023-11-03 11:08:37 27 4
gpt4 key购买 nike

我正在创建一个 WCF 服务,昨天它似乎在 VS 测试客户端上运行良好,但今天它似乎在我尝试更改 web.config 文件后抛出此错误。

下面是代码和配置文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace TSService
{
interface name "IService1" in both code and config file together.
[ServiceContract]
public interface ITSService

[OperationContract]
List<Sel_Test> RunScript(List<SName> SNamesToRun, int LogPathIndex, RunEnvironment EnvironmentName, BOptions BType, NavOption NavEnum);

}

[DataContract]
public class STest
{
[DataMember]
public ScriptName SName { get; set; }
[DataMember]
public BOptions BTypeUsed { get; set; }
[DataMember]
public int SResult { get; set; }
}

[DataContract(Name= "SName")]
public enum SName
{
[EnumMember]
PXXXX1,
[EnumMember]
PXXXX2,
[EnumMember]
PXXXX3,
[EnumMember]
PXXXX4

}

[DataContract]
public enum NavOption
{
[EnumMember]
ContinueToNext,
[EnumMember]
Skip,
[EnumMember]
SignIn,
[EnumMember]
Registration
}

[DataContract]
public enum BOptions
{
[EnumMember]
FAA1,
[EnumMember]
ReFi,
[EnumMember]
RIE
}

[DataContract]
public enum RunEnvironment
{
[EnumMember]
D,
[EnumMember]
Q,
[EnumMember]
S,
[EnumMember]
P
}
[DataContract]
public enum PType
{
[EnumMember]
MAPD,
[EnumMember]
PDP,
[EnumMember]
MA,
[EnumMember]
Mgap
};
}

在我的配置文件中:

<system.serviceModel>

<behaviors>
<serviceBehaviors>
<behavior name="TSServiceBehavior">
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>

<services>
<service name="TSService.ITSService" behaviorConfiguration="TSServiceBehavior">
<endpoint address=""
binding ="basicHttpBinding"
contract="TSService.ITSService" />

<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>


<bindings>
<basicHttpBinding>
<binding name ="TSServiceBinding" receiveTimeout="00:20:00" sendTimeout="00:20:00">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>


<!--<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>-->
<serviceHostingEnvironment aspNetCompatibilityEnabled="False" multipleSiteBindingsEnabled="true"/>
</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>



<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>

在 SVC 标记中我有:

<%@ ServiceHost Language="C#" Debug="true" Service="TSService.ITSService" CodeBehind="TSService.svc.cs" %>

我在运行 VS WCFTest 客户端时遇到的错误:

Error: Cannot obtain Metadata from http://localhost:55178/TSService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:55178/TSService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:55178/TSService.svc'. The requested service, 'http://localhost:55178/TSService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:55178/TSService.svc There was an error downloading 'http://localhost:55178/TSService.svc'. The request failed with the error message:-- 
Server Error in '/' Application.
--------------------------------------------------------------------------------

ServiceHost only supports class service types.
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.ArgumentException: ServiceHost only supports class service types.

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:

[ArgumentException: ServiceHost only supports class service types.] System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +12912843 System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +58 System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +146 System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +46 System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +146 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +30 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +494 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 '/TSService.svc' cannot be activated due to an exception during compilation. The exception message is: ServiceHost only supports class service types..] System.Runtime.AsyncResult.End(IAsyncResult result) +495736 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178 System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +348782 System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9662977



--------------------------------------------------------------------------------
Version Information:ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034 --.

最佳答案

根据评论将此标记为已回答 - “我通过在标记中将 ITSService 更改为 TSSErvice 来消除此错误。”

关于c# - ServiceHost 只支持类服务类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864444/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com