我有一个旧的ASP.NET网站,该网站具有用于返回JSON有效负载的WCF服务。它在localhost上运行良好,但是当我尝试将其部署到共享托管网站时,出现异常:
IIS指定了身份验证方案“ IntegratedWindowsAuthentication,Basic,Anonymous”,但是绑定仅支持仅指定一种身份验证方案。有效的身份验证方案为摘要,协商,NTLM,基本或匿名。更改IIS设置,以便仅使用单个身份验证方案。
我无法进行此更改,因为它是共享环境。
关于服务,我是否需要更改Web.config
中的配置?这就是我所拥有的:
<system.serviceModel>
<services>
<service name="BoggleService">
<endpoint binding="webHttpBinding" contract="Solver" behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我也有这个配置,但是它被注释掉了(就像我说的,一个很久以前的项目,试图将其复活):
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.example.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
但是,如果我取消注释并包含它,则在 localhost和共享托管网站中都会收到以下异常:
索引超出范围。必须为非负数,并且小于集合的大小。
这是完整的堆栈跟踪:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64
System.ThrowHelper.ThrowArgumentOutOfRangeException() +15
System.Collections.Generic.List`1.get_Item(Int32 index) +7515544
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage) +82
System.ServiceModel.Web.WebServiceHost.OnOpening() +203
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 '/Solver.svc' cannot be activated due to an exception during compilation. The exception message is: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index.]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11667006
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) +275
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
这来自WCF的内部-不是来自我的代码(堆栈跟踪显示它永远不会到达我的代码,如果我运行调试器并在代码中设置断点,则永远不会到达)
有趣的是,如果我将<baseAddressPrefixFilters>
设置设置为http://localhost
,它将在localhost上运行!但是没有生产。
谢谢!
答案 0 :(得分:0)
我认为可以解决此问题,因为它使用WebHttpBinding托管Restful样式服务。
在.net4.5中,我们可以使用以下简化的配置来托管Restful样式服务。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
默认情况下,Webhttp绑定使用WebHttpSecurityMode.None。因此,不太可能发生上述身份验证架构错误。如有必要,请不要忘记在IIS身份验证模块中启用身份验证模式。
尝试用我的配置替换您的配置,并在IIS网站绑定模块中提供http绑定。
随时告诉我是否有什么可以帮助的。