[英]Visual Studio 2013 C# WCF web service _vti_bin/ListData.svc/$metadata
上下文如下:
創建WCF服務:Framework .NET 4.0
當我使用Visual Studio 2010
開發解決方案時,一切正常,一切都按預期進行。
我使用Visual Studio 2013重建了解決方案,現在由於引用要查詢憑據的Web服務而不再起作用:
檢查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服務器上打開URL時在網頁上看到的錯誤:
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並重新部署了匿名身份驗證,那么一切都很好。
使用Web服務肯定有些麻煩,但是我的選擇已經用光了...
基於此:
我需要禁用“匿名身份驗證”並啟用“ Windows身份驗證”
在配置文件的<system.web>
部分中,將此添加到<authentication mode="Windows">
:
<system.web>
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<pages />
<identity impersonate="false" />
</system.web>
現在,在<system.webServer>
部分中,添加以下<security>
節點:
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
它可能對您不起作用,但是對我來說,這只是解決了一周的頭痛問題。
好吧,終於我解決了這個問題...但是您不會喜歡它。 基本上,相同的解決方案僅在IIS 8.0下運行良好。 這意味着您必須安裝Win Server 2012等。此外,不要忘記在屬性中設置“ Windows Authenticated” = Enabled。
這是我設法使其正常工作的唯一方法...對不起。
將項目從VS2010轉換為VS2013時,出現了相同的問題( ../_vti_bin/ListData.svc/$metadata要求提供憑據)。 我的問題來自將clientCredentialType設置為“ Ntlm”而不是“ Windows”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.