WCF服务404错误

时间:2012-04-09 21:53:36

标签: wcf http service handler

我正在尝试设置WCF服务,但我遇到了一些问题。当我输入

时,该服务工作并加载wsdl页面
www.mydomain.com/Service1.svc

但是当我使用

www.mydomain.com/Service1.svc/

或尝试使用我得到的任何get方法

The resource cannot be found.

Description: HTTP 404.

我的web.config文件如下

<?xml version="1.0"?>
<configuration>

  <system.webServer>
    <handlers>
      <remove name="PageHandlerFactory-ISAPI-4.0"/>
      <add name="PageHandlerFactory-ISAPI-4.0" path="*" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <remove name="ASP.NET-ISAPI-4.0-Wildcard"/>
      <add name="ASP.NET-ISAPI-4.0-Wildcard"
         path="*" verb="GET,HEAD,POST,DEBUG"
         modules="IsapiModule"
         scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
         preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <remove name="svc-Integrated-4.0" />
      <add name="svc-Integrated-4.0" path="*" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <httpHandlers>
      <remove verb="*" path="*.svc"/>
      <add path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false" />
    </httpHandlers>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RestService.Service1" behaviorConfiguration="ServiceBehaviour" >
        <endpoint address="" binding="webHttpBinding" contract="RestService.IService1" behaviorConfiguration="web">

        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://mydomain.com/Service1"/>
          </baseAddresses>
        </host>
      </service>

    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour" >
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>



    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Service.svc文件如下:

namespace RestService
{
    public class Service1 : IService1
    {
        public bool LoginUser( string Username, string password )
        {
            return true;
        }
    }
}

和IService.cs如下:

namespace RestService
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            //BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "login/{username}/{password}")]
        bool LoginUser(string username, string password);
    }
 }

如果有帮助,服务器上的管道模式是“集成”。我不确定我的托管服务提供商(pipeten)使用的IIS版本是什么,但我认为它是7.5我觉得这与URL验证有关,但我的托管上没有选项来改变它。

1 个答案:

答案 0 :(得分:2)

好吧事实证明这是我犯过的一个简单的错误,我错过了。添加处理程序时。而不是path =“”它应该是path =“。

<add name="ASP.NET-ISAPI-4.0-Wildcard"
         path=".*" verb="GET,HEAD,POST,DEBUG"
         modules="IsapiModule"
         scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
         preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />