我正在学习 WCF,并使用 Visual Studio 2008 及其 Web 服务器在我的开发环境中运行以下代码。当我将 Web 服务发布到 IIS 6 时,所有请求都会导致 400“错误请求”错误。查看 IIS 日志,状态码是 400,win32-status 码是 1380。使用net helpmsg 1380
,它告诉我 wind32 状态码的意思是“登录失败:在这台计算机上没有授予用户请求的登录类型”。但我正在使用webHTTPBinding的 REST,它不使用身份验证或安全方法。
在 IIS 中,我将应用程序设置为允许匿名,该应用程序设置为模拟“IUSER_<machine_name>”帐户。在应用程序池中,我将其设置为使用网络服务标识。两个用户都设置为写入访问临时文件夹以及 .net 框架文件夹。我已经设置了 WCF 跟踪,但日志是空白的。我正用头撞墙。有人可以帮忙吗?
web.config 的 System.ServiceModel 部分:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="default" name="GTKK.ServiceLibrary.GTKKService">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="" name="web" contract="GTKK.ServiceLibrary.IGTKKService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1173/GTKKService" />
</baseAddresses>
</host>
</service>
</services>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
</system.serviceModel>
这是我的服务合同:
using GTKK.DTO;
using System.ServiceModel.Web;
namespace GTKK.ServiceLibrary
{
[ServiceContract(SessionMode=SessionMode.Allowed)]
public interface IGTKKService
{
[WebGet(UriTemplate = "artist/{id}/json", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
ArtistDTO GetArtistByID(string id);
[WebGet(UriTemplate = "artists/json?namefilter={namefilter}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
List<ArtistDTO> GetArtistListByNameFilter(string nameFilter);
[WebGet(UriTemplate = "localevents/json?search={searchText}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
List<EventDTO> GetLocalEventsBySearchLocationJson(string searchText);
[WebGet(UriTemplate = "localevents/xml?search={searchText}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml)]
[OperationContract]
List<EventDTO> GetLocalEventsBySearchLocationXml(string searchText);
}
}
在浏览器中,我使用以下 URL 在我的开发环境中使用 VS2008 Web 服务器进行测试,它可以工作:
http://localhost:1173/GTKKService/localevents/xml?search=98101
发布到 IIS 并使用以下 url 后,我得到了错误的请求页面:
http://<host_name>/service.svc/localevents/xml?search=98101
我知道 url 应该是正确的,就好像我在 .svc 部分之后输入了一个错误的 url,我会得到一个未找到端点的错误,它正在按应有的方式工作。例如:
http://<host_name>/service.svc/anythinghere
IIS 服务器盒安装了 .net 2、3.0 和 3.5。IIS Web 应用程序设置为使用 .net 2(将使用 .net 3.5)。我还运行了 serviceModelReg /i /x 以及 /ia 以确保 WCF 已安装和注册。关于“Bad Request”错误页面的问题在于它不是 IIS 错误页面,它的 HTML 格式类似于 WCF 错误页面,顶部有一个深蓝色条,白色标题为“ Request Error ”,然后是消息“ The服务器在处理请求时遇到错误。有关详细信息,请参阅服务器日志。 "
请帮忙。