1

我正在尝试设置 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 验证有关,但是我的托管服务上没有选项可以更改它。

4

1 回答 1

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" />
于 2012-04-14T14:59:25.493 回答