1

我正在学习 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服务器在处理请求时遇到错误。有关详细信息,请参阅服务器日志。 "

请帮忙。

4

1 回答 1

0

问题已解决。由于错误页面是 WCF 生成的,我认为请求必须发送到服务主机。但是我有任何错误的事件日志记录,并且事件日志中没有。这有点困扰我。所以我添加了另一个 OperationContract,它只返回程序集名称和版本号,不进行任何处理。在浏览器中调用时,新操作返回装配数据。嗯。所以这是有效的。其他操作有什么问题?为了查看其他人的数据处理有什么问题,我不得不安装远程调试并启动远程调试过程。来发现是数据库连接字符串导致登录失败错误。我正在使用集成安全性进行数据库连接。我认为它会使用为应用程序池设置的网络服务帐户。但令我惊讶的是,当使用没有安全设置的 webHTTPBinding 时,它使用了隐藏域计算机帐户。一旦我解决了数据连接问题,所有操作都运行良好。此外,我发现我的事件日志记录也无法正常工作,因为没有记录到事件日志的权限。所以我从来没有在事件日志中得到任何东西。这就是让我一开始就偏离轨道的原因。好吧,我现在是一个快乐的露营者。:) 由于缺乏登录事件日志的权限而无法正常工作。所以我从来没有在事件日志中得到任何东西。这就是让我一开始就偏离轨道的原因。好吧,我现在是一个快乐的露营者。:) 由于缺乏登录事件日志的权限而无法正常工作。所以我从来没有在事件日志中得到任何东西。这就是让我一开始就偏离轨道的原因。好吧,我现在是一个快乐的露营者。:)

于 2011-02-17T02:29:19.807 回答