且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS下托管的WCF REST服务生成身份验证错误

更新时间:2023-12-01 14:17:34

我的一个.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