IIS下托管的WCF REST服务生成身份验证错误 [英] WCF REST services hosted under IIS generates authentication errors

查看:94
本文介绍了IIS下托管的WCF REST服务生成身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试在IIS 5下使用Visual Studio 2008托管RESTfull服务,但没有成功.

这就是服务要做的(非常简单):

[ WebGet (BodyStyle = WebMessageBodyStyle .Bare,UriTemplate = "/date"

RequestFormat = WebMessageFormat .Xml,ResponseFormat = WebMessageFormat .Xml)]

公共 字符串 GetData()

{

返回 字符串 .Format( "当前时间:{0}" DateTime .Now.ToString());

}

使用非配置方法,我使用以下标记定义了.svc文件:

<% @ ServiceHost 语言 ="C#" 调试 ="true" 服务 =" WcfService2.Service1" CodeBehind =" Service1.svc.cs"

Factory =" System.ServiceModel.Activation.WebServiceHostFactory" %>

该工厂负责使用webHttpBinding创建提供REST服务的终结点.

在ASP.NET托管服务器下的

: http://localhost:17562/Service1.svc/date 将生成以下输出:

< 字符串 xmlns =&; http://schemas.microsoft.com/2003/10/Serialization/ "" > 当前时间:4/24/2008 2: 38:38 PM </ 字符串 这正是所需要的.不幸地转移到IIS托管而完全没有更改会产生以下错误:

http ://localhost/WcfService2/Service1.svc/date -找不到404.

http://localhost /WcfService2/Service1.svc - " IIS指定了身份验证方案'IntegratedWindowsAuthentication,Anonymous',但绑定仅支持指定一种身份验证方案.有效的身份验证方案为摘要,协商,NTLM,基本或匿名.更改IIS设置,以便仅使用单个身份验证方案."

我已取消IIS上的Windows集成安全性,并在Visual Studio http://localhost/WcfService2/Service1.svc -拒绝访问401 .

< system.serviceModel >

< 服务 >

< 服务 名称 = " WcfService2.Service1 " behaviorConfiguration = " Service1行为 " >

< 端点

地址 = "" ;

行为配置 = " epBehavior "

绑定 = " webHttpBinding "

合同 = " WcfService2.IService1 " />

< 端点 地址 = " mex " 绑定 = " mexHttpBinding " 合约 = " IMetadataExchange " <字体color =#0000ff" size = 2>/>

</ 服务 >

</ 服务 >

< 行为 >

< endpointBehaviors >

< 行为 名称 = " epBehavior " >

< webHttp />

</ 行为 >

</ endpointBehaviors >

< serviceBehaviors >

< 行为 名称 = " Service1Behavior " >

< serviceMetadata httpGetEnabled = " true " />

< serviceDebug includeExceptionDetailInFaults = " true " />

</ 行为 >

</ serviceBehaviors >

</ 行为 >

</ system.serviceModel >

再次按F5 + CTRL- http://localhost/WcfService2/Service1.svc 与wsdl的链接也有效. http://localhost/WcfService2/Service1.svc/date 仍返回404.我什至尝试创建自己的自定义工厂,并在其中创建代码具有webHttpBinding但没有成功的端点.我无法在IIS下使用REST.这在Visual Studio 2005中也使用过,并产生了相同的错误.

我在这里做什么错?是IIS 5吗?

谢谢

Nir ​​

解决方案

我的一个.scv出现了相同的问题,但我对它

喜欢> 1.在"Virutal Dir的身份验证方法"中取消选中集成Windows身份验证",并选中启用匿名访问者"
2.我注释掉了< authentication mode =''Windows''/>在我的web.config中


希望它对您有用
TUW3


Hello,

I'm trying host a RESTfull service using visual studio 2008 under IIS 5 with no success.

 

That's what the service do (very much simple):

[WebGet(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/date",

RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]

public string GetData()

{

return string.Format("Current time: {0}", DateTime.Now.ToString());

}

 

Using a non-config approach i defined the .svc file with the following tag:

<%@ ServiceHost Language="C#" Debug="true" Service="WcfService2.Service1" CodeBehind="Service1.svc.cs"

Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

 

This factory is responsible for creating an endpoint with webHttpBinding that provides the REST services.

under asp.net hosting server: http://localhost:17562/Service1.svc/date will generate the following output:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Current time: 4/24/2008 2:38:38 PM</string>

which is exactly what is needed. unfortunatelly moving to IIS hosting with no changes at all generates the following error:

http://localhost/WcfService2/Service1.svc/date - 404 not found.

http://localhost/WcfService2/Service1.svc - "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."

I've canceled the windows integrated security on IIS and hit F5+CTRL on visual studio http://localhost/WcfService2/Service1.svc - Access denied 401.

http://localhost/WcfService2/Service1.svc/date - 404 not found.

 

so then I tried a different approach - the config way. I removed the WebServiceHostFactory from the .svc file, updated IIS for windows integrated and anonymous again, and add this configuration block:

 

<system.serviceModel>

<services>

<service name="WcfService2.Service1" behaviorConfiguration="Service1Behavior">

<endpoint

address=""

behaviorConfiguration="epBehavior"

binding="webHttpBinding"

contract="WcfService2.IService1" />

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

</service>

</services>

<behaviors>

<endpointBehaviors>

<behavior name="epBehavior">

<webHttp />

</behavior>

</endpointBehaviors>

<serviceBehaviors>

<behavior name="Service1Behavior">

<serviceMetadata httpGetEnabled="true"/>

<serviceDebug includeExceptionDetailInFaults="true"/>

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

 

hit F5+CTRL again - http://localhost/WcfService2/Service1.svc returns the service default page with link to the wsdl that also works. http://localhost/WcfService2/Service1.svc/date still returns 404. I even tried creating a custom factory of my own in which I create in code an endpoint with webHttpBinding but with no sucess. I can't get the REST to work under IIS. this was also used in visual studio 2005 and generated the same errors.

What do I do wrong here? is it the IIS 5?

Thanks,

Nir

解决方案

I had the same problem with one of my .scv, but I resloved it by

1. unchecking Integrated Windows Authenication in Authentication Methods for the Virutal Dir and left Enable anonymous acceess checked
2.  I commented out  <authentication mode="Windows"/>  in my web.config


Hope it works for you
TUW3


这篇关于IIS下托管的WCF REST服务生成身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆