【问题标题】:Visual Studio 2013 C# WCF web service _vti_bin/ListData.svc/$metadataVisual Studio 2013 C# WCF Web 服务 _vti_bin/ListData.svc/$metadata
【发布时间】:2015-01-16 18:51:31
【问题描述】:

上下文如下:

创建 WCF 服务:框架 .NET 4.0

  • 在 IIS 7 下部署
  • Web 服务包含
  • 对检索数据集的库的引用
  • WCF 使用数组中的方法
  • 我需要禁用“匿名身份验证”并启用“Windows 身份验证”
  • 我将服务作为 Web 服务使用(我不想使用 svcutil 生成的文件)
  • Web 服务的端点是“mywebpoint/mywcf_web_service.svc”

当我使用Visual Studio 2010 开发解决方案时,一切正常,一切正常。

我使用 Visual Studio 2013 重建解决方案,现在它不再工作,因为它引用了它要求提供凭据的 Web 服务:

  • “mywebpoint/mywcf_web_service.svc/_vti_bin/ListData.svc”和
  • “mywebpoint/mywcf_web_service.svc/_vti_bin/ListData.svc/$metadata”

检查了 DNS 和代理身份验证...没有任何问题

这里是 Web.Config:


<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

    <webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
        <add name="HttpSoap12" />
        <add name="HttpSoap" />
      </protocols>
    </webServices>

    <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm" />
  </system.web>

  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="myBasicHttpBinding" bypassProxyOnLocal="true">
          <security mode="TransportCredentialOnly">
          <!--<security mode="Transport">-->
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service name="WCF_MyWebService.Service" behaviorConfiguration="WCF_MyWebService.ServiceBehaviour">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBasicHttpBinding" name="BasicHttpEndpoint" contract="WCF_MyWebService.IService" >
          <identity>
            <dns value="" />
          </identity>
        </endpoint>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> ??? I didn't need this with Visula Studio 2010!!!
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="WCF_MyWebService.ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment 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>



</configuration>

这里是我在网页上遇到的错误,我尝试在 IIS 服务器上打开网址:


Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service. 
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.NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

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: 


[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) +198236
   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 '/WCF_Excelnet_CoreSvc/WCF_Excelnet_Core.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) +178638
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107

这真是令人沮丧和失望......

如果我清理好 Web.confing 并重新设置匿名身份验证,那一切都很好。

肯定有什么东西在消耗网络服务,但我已经没有选择了......

【问题讨论】:

  • 如果您打开适用于 vs2010 的版本会发生什么情况 在 vs2013 中打开它并且如果出现转换对话框让 vs2013 处理它也请查看此链接是否有帮助msdn.microsoft.com/en-us/library/vstudio/…
  • 运行您的服务的应用程序池的身份是否可以访问服务的物理文件夹?
  • 知道为什么 _vti_bin 是图片的一部分吗?此处是否涉及 SharePoint?
  • MethodMan:第一个工作版本是用 vs2010 制作的。我可以用 vs2013 打开它,直到我没有重建版本一切都好。该死的,我在 WCF 中添加了一个方法,并且我使用 vs2013 完成了它......并且因为所有问题都开始了......
  • Pankaj Kapare:是的

标签: c# web-services wcf visual-studio-2013 metadata


【解决方案1】:

基于此:

我需要禁用“匿名身份验证”并启用“Windows 身份验证”

在配置文件的&lt;system.web&gt; 部分,在&lt;authentication mode="Windows"&gt; 下方添加:

<system.web>
  <authentication mode="Windows" />
  <authorization>
    <allow users="*" />
  </authorization>
  <pages />
  <identity impersonate="false" />
</system.web>

现在,在&lt;system.webServer&gt; 部分,添加这个&lt;security&gt; 节点:

<system.webServer>
    <security>
        <authentication>
            <anonymousAuthentication enabled="false" />
        </authentication>
    </security>
</system.webServer>

它可能对你不起作用,但对我来说,这只是解决了一周的头痛。

【讨论】:

  • 您好 jp2code,我刚刚尝试过,关于第一部分,它似乎没有任何效果。相反,第二部分创建了另一个问题:>overrideModeDefault="Deny"
  • 转到我的answer on another question 看看是否有任何帮助(来自我的帖子或其他任何人)。
【解决方案2】:

好吧,我终于解决了这个问题......但你不会喜欢它。 基本上相同的解决方案仅在 IIS 8.0 下运行良好。 这意味着您必须安装 Win Server 2012 等... 另外,不要忘记在属性中设置“Windows Authenticated”=启用。

这是我设法使它工作的唯一方法......对不起。

【讨论】:

    【解决方案3】:

    在将项目从 VS2010 转换为 VS2013 时,我遇到了同样的问题(../_vti_bin/ListData.svc/$metadata 要求提供凭据)。我的问题来自 clientCredentialType 设置为“Ntlm”而不是“Windows”。

    【讨论】:

      猜你喜欢
      • 2013-10-25
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      相关资源
      最近更新 更多