WCF服务404错误

问题描述:

我想建立一个WCF服务,但我有几个问题。该服务的工作原理,并加载WSDL页面,当我在WCF服务404错误

www.mydomain.com/Service1.svc 

键入然而,当我使用

www.mydomain.com/Service1.svc/ 

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

The resource cannot be found. 

Description: HTTP 404. 

我的网站.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验证有关,但是在我的托管上没有选项可以更改此选项。

+0

表现出一定的服务方法和正在创建的请求URL。 – Chandermani 2012-04-10 05:12:03

+0

你在IIS上托管吗?还要指定您的IIS版本和您的环境 – Rajesh 2012-04-10 09:04:40

+0

我已添加更多信息来显示我创建的方法! – kiwijus 2012-04-10 18:36:05

好吧原来这是我犯的一个简单的错误,我错过了。添加处理程序时。相反路径=“”它应该是路径=“”的

<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" />