programing

WCF 웹 서비스 오류:서비스가 ASP를 지원하지 않으므로 활성화할 수 없습니다.NET 호환성

telecom 2023. 9. 2. 07:59
반응형

WCF 웹 서비스 오류:서비스가 ASP를 지원하지 않으므로 활성화할 수 없습니다.NET 호환성

저는 편안한 wcf 웹 서비스를 만들려고 합니다.클라이언트를 통해 서비스에 연결하려고 하면 다음 오류가 발생합니다.

서비스가 ASP를 지원하지 않으므로 활성화할 수 없습니다.NET 호환성.이 응용 프로그램에 대해 ASP.NET 호환성이 사용되도록 설정되었습니다.ASP를 끕니다.web.config의 NET 호환성 모드 또는 AsNetCompatibilityRequirements 특성을 RequirementsMode 설정이 'Allowed' 또는 'Required'인 서비스 유형에 추가합니다.

다른 사람들은 문제가 있었지만, 그들은 그들의 web.config의 변경을 통해 그것을 고쳤습니다.저는 그들의 수정 사항을 이행했지만 여전히 문제가 존재합니다.다음은 나의 web.config입니다.

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebBehavior" >
           <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="MyServiceBehavior" name="myfirstwcf">
        <endpoint address="ws" binding="basicHttpBinding" 
                  contract="Imyfirstwcf" />
        <endpoint address="ws2" binding="wsHttpBinding" 
                  contract="Imyfirstwcf" />
        <endpoint address="" behaviorConfiguration="WebBehavior" 
                  binding="webHttpBinding" 
                  contract="Imyfirstwcf" />
        <endpoint address="mex" binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled= "true"
      multipleSiteBindingsEnabled="true"  />
  </system.serviceModel>

기본 서비스에서 서비스를 다음과 같이 표시할 수 있습니다.

[AspNetCompatibilityRequirements(
        RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

출처: http://forums.silverlight.net/t/21944.aspx

작동할 것입니다.

코드에서 이 줄을 변경하거나 web.config에 줄을 추가해야 합니다.

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel>

다른 사용자가 많은 서비스를 가지고 있고 사용자 정의를 사용하여 서비스를 생성하는 경우ServiceHostFactory,그리고나서AspNetCompatibilityRequirementsAttribute에서 설정할 수도 있습니다.CreateServiceHost방법.

예:

public class HostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        var host = new ServiceHost(serviceType, baseAddresses);
        //other relevent code to configure host's end point etc
        if (host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute)))
        {
            var compatibilityRequirementsAttribute = host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute;
            compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
        }
        else
        {
            host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute() { RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed});
        }
        return host;
    }
}

사실, 최근 문서에 따르면 당신이 해야 할 일은 두 가지입니다.

1.서비스 클래스의 경우:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(Namespace = "url")]
public class Service : IService
{
}

2.web.config용

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

언급URL : https://stackoverflow.com/questions/11904202/wcf-web-service-error-the-service-cannot-be-activated-because-it-does-not-suppo

반응형