0

WCF サービスを作成しましたが、匿名アクセスを無効にするように設定しようとしています。アプリケーションにサービス参照を追加しようとすると、次のエラーが発生します。

このサービスのセキュリティ設定には「匿名」認証が必要ですが、このサービスをホストする IIS アプリケーションでは有効になっていません。

以下は、私の WCF サービスの構成ファイルです。

<?xml version="1.0"?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="All"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:\log\Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
      <authentication mode="Windows"/>
      <customErrors mode="Off" />
  </system.web>
    <appSettings>

    </appSettings>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyBinding">
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Windows" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="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>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Windows 認証を使用するには、何を変更する必要がありますか?

編集*

ジェフ、これが私のエラーメッセージです:

The request failed with the error message:
--
<html>
    <head>
        <title>Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.</title>
        <style>
            body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
            p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
            b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
            H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
            H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
            pre {font-family:"Lucida Console";font-size: .9em}
            .marker {font-weight: bold; color: black;text-decoration: none;}
            .version {color: gray;}
            .error {margin-bottom: 10px;}
            .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

        <span>
            <H1>
                Server Error in '/' Application.<hr width="100"% size="1" color="silver">
            </H1>

            <h2>
                <i>Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.</i>
            </h2>
        </span>

        <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>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.

            <br>
                <br>

                    <b> Exception Details: </b>System.NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.<br>
                        <br>

                            <b>Source Error:</b>
                            <br>
                                <br>

                                    <table width="100"% bgcolor="#ffffcc">
                                        <tr>
                                            <td>
                                                <code>

                                                    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.
                                                </code>

                                            </td>
                                        </tr>
                                    </table>

                                    <br>

                                        <b>Stack Trace:</b>
                                        <br>
                                            <br>

                                                <table width="100"% bgcolor="#ffffcc">
                                                    <tr>
                                                        <td>
                                                            <code>
                                                                <pre>

                                                                    [NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.]
                                                                    System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpSettings(String virtualPath, Boolean isMetadataListener, Boolean usingDefaultSpnList, AuthenticationSchemes& supportedSchemes, ExtendedProtectionPolicy& extendedProtectionPolicy, String& realm) +198300
                                                                    System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(String virtualPath, Boolean isMetadataListener) +104
                                                                    System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener(BindingContext context) +156
                                                                    System.ServiceModel.Channels.Binding.BuildChannelListener(Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) +166
                                                                    System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession) +393
                                                                    System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +583
                                                                    System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +2020
                                                                    System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
                                                                    System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +64
                                                                    System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
                                                                    System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +255
                                                                    System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172

                                                                    [ServiceActivationException: The service '/SLtoCRM.svc' cannot be activated due to an exception during compilation.  The exception message is: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service..]
                                                                    System.Runtime.AsyncResult.End(IAsyncResult result) +901424
                                                                    System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178702
                                                                    System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107
                                                                </pre>
                                                            </code>

                                                        </td>
                                                    </tr>
                                                </table>

                                                <br>

                                                    <hr width="100"% size="1" color="silver">

                                                        <b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237

                                                    </font>

    </body>
</html>
<!-- 
[NotSupportedException]: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.
   at System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpSettings(String virtualPath, Boolean isMetadataListener, Boolean usingDefaultSpnList, AuthenticationSchemes& supportedSchemes, ExtendedProtectionPolicy& extendedProtectionPolicy, String& realm)
   at System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(String virtualPath, Boolean isMetadataListener)
   at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
   at System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
   at System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession)
   at System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
[ServiceActivationException]: The service '/SLtoCRM.svc' cannot be activated due to an exception during compilation.  The exception message is: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service..
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
   at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
--><!-- 
This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
--.
Metadata contains a reference that cannot be resolved: 'xxxx/SLtoCRM.svc'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again.

新しい WCF サービスを作成しようとしましたが、同じ問題が発生しています。WCF サービスの更新された構成ファイルは次のとおりです。

    <?xml version="1.0"?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="All"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:\log\Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
      <customErrors mode="Off" />

      <authentication mode="Windows" />
      <authorization>
          <allow users="*" />
      </authorization>
  </system.web>
    <appSettings>
    </appSettings>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyBinding">
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Windows" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <services>
            <service name="SLtoCRM">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoCRM" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
            <service name="SLtoSQL">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoSQL" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="CRMBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="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>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

念のため、エンドポイントで使用されている私のインターフェイスの 1 つを次に示します。

namespace CRMWCF
{
    [ServiceContract]
    public interface ISLtoSQL
    {
        [OperationContract]
        IEnumerable<Dictionary<string, string>> GetOptionSet(string connectionString, int objectTypeCode, string optionSetName);

    }
}

このサービスを追加しようとしているアプリケーションの構成ファイルで何かを行う必要がありますか?

ありがとう

4

1 に答える 1

0

Services セクションを追加する必要があります。このようにして、Service エンドポイントを指定し、作成したバインディング構成を使用するように指示できます。

    <System.ServiceModel>
    <services>
          <service name="ServiceName" >
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="namespace.IContract" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
    </System.ServiceModel>
于 2013-05-02T20:50:51.793 に答える