asp.net - 使用 POST/JSON 在 2003 上托管 WCF Rest 服务

标签 asp.net iis wcf-rest

因为我在 Win 2003 服务器上托管 WCF 服务时遇到问题。 因为它在我的本地电脑上运行良好。

如果我需要对 Web Config 进行任何更改,请立即告诉我。文件。对于同样的。

“/”应用程序中的服务器错误。 IIS 指定了身份验证方案“IntegratedWindowsAuthentication、Anonymous”,但绑定(bind)仅支持指定一种身份验证方案。有效的身份验证方案包括摘要、协商、NTLM、基本或匿名。更改 IIS 设置,以便仅使用单一身份验证方案。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.InvalidOperationException:IIS 指定了身份验证方案“IntegratedWindowsAuthentication,Anonymous”,但绑定(bind)仅支持指定一种身份验证方案。有效的身份验证方案包括摘要、协商、NTLM、基本或匿名。更改 IIS 设置,以便仅使用单一身份验证方案。

来源错误:

执行当前 Web 请求期间生成未处理的异常。有关异常来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

堆栈跟踪:

[InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.]
   System.ServiceModel.Web.WebServiceHost.SetBindingCredentialBasedOnHostedEnvironment(ServiceEndpoint serviceEndpoint, AuthenticationSchemes supportedSchemes) +446264
   System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage) +709
   System.ServiceModel.Web.WebServiceHost.OnOpening() +203
   Microsoft.ServiceModel.Web.WebServiceHost2.OnOpening() in e:\bt\3781\Microsoft.ServiceModel.Web\Microsoft.ServiceModel.Web\WebServiceHost2.cs:69
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +229
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +121
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479

[ServiceActivationException: The service '/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used..]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +11599786
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3618 

最佳答案

有一个快速修复和一个正确的修复。

快速修复:

在 IIS 中,转到运行该服务的 Web 应用程序的属性,转到“目录安全性”选项卡,然后在“身份验证和访问控制”组中按“编辑...”。删除您不需要的任何身份验证方案。确定所有对话后,然后执行 IIS 重置。

正确修复:

确保您的服务配置为使用显式端点。我发现使用开箱即用的 webHttpBinding 绑定(bind),并将端点配置为使用 webHttp 行为就是诀窍。

如果您不指定端点,WebserviceHost 将尝试猜测您想要什么,并且总是会选择错误的端点。

在你的 web.config 中,你应该有类似的内容:

<system.serviceModel>
  <services>
    <service behaviourConfiguration="MyRestService.Behavior" 
             name="MyRestService>
      <endpoint address="" binding="webHttpBinding" contract="IMyRestService"
                behaviourConfiguration="MyRestService.WebHttpEndpointBehavior" />
    </service>
  </services>
  <bindings>
  </bindings>
  <behaviours>
    <serviceBehaviors>
      <behavior name="MyRestService.Behavior">
        <!-- Any configuration for the service, i.e. serviceDebug, etc. -->
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="MyRestService.WebHttpEndpointBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviours>
</system.serviceModel>

当然,这样的配置设置使我能够在安装了 .NET 3.5 SP1 的 Win2k3 服务器上运行 WCF REST 服务。

关于asp.net - 使用 POST/JSON 在 2003 上托管 WCF Rest 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5377081/

相关文章:

jquery - DOMContentLoaded 在 Chrome 中非常慢

asp.net - 如何更改 ClickOnce list 文件中的部署提供程序 url?

c# - 如何在基于浏览器的 url 中将自定义对象发送到 WCF REST 服务

c# - WCF 托管和性能

c# - RESTful 服务问题

asp.net - 尝试在 asp.net 中创建 json Web 服务时出错

c# - 在 ASP.NET 应用程序中将图像从 JavaScript 传递到 C#?

javascript - html5音频隐藏下载按钮

http - 如何通过 iis 禁用 http 方法

asp.net - iis 7.5 ASP.net 挂起请求