运行 IIS 上的 WCF WebService,HTTP 错误 404.0 - 未找到

Run WCF WebService on IIS ,HTTP Error 404.0 - Not Found

我有一个使用 JSON 格式的 WCF WebService。 我可以 运行 它在 Visual Studio 2013 中正确但是当我通过我的机器本地 ip 和特定端口 (192.168.1.6:8005) 将它发布到 IIS 到 运行 以从本地访问它时此地址的网络:

 http://192.168.1.6:8005/Service1.svc/checkLogin?username=2&password=2&code=1

这是错误:

 HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information
Module  IIS Web Core
Notification    MapRequestHandler
Handler StaticFile
Error Code  0x80070002
Requested URL   http://192.168.1.6:8005/Service1.svc/checkLogin?kodemelli=2&password=2&bank_hesab_number=1
Physical Path   E:\testjson\Service1.svc\checkLogin
Logon Method    Anonymous
Logon User  Anonymous

三个文件即:Service1.svc、Web.config 和 JSONSample.dll 存在于其 IIS 网站的物理路径中。

这是我的 web.config :

 <?xml version="1.0"?>
<!-- Copyright ©) Microsoft Corporation.  All Rights Reserved. -->
<configuration>
  <system.serviceModel>    
    <behaviors>
  <serviceBehaviors>
    <behavior name="JSONSample.Service1Behavior">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="Web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service name="JSONSample.Service1" behaviorConfiguration="JSONSample.Service1Behavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.1.6:8005/Service1" />
      </baseAddresses>
    </host>
    <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" contract="JSONSample.IService1">
      <identity>
        <dns value="192.168.1.6"/>
      </identity>
    </endpoint>
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
  </service>
</services>
  </system.serviceModel>
  <system.web>
<compilation debug="true"/>
  </system.web>
  <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

和IService.cs的一部分:

public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "checkLogin?username={username}&password={password}&code={code}")]
    string checkLogin(string username, string password, string code); 

我看了很多文章和主题来解决这个问题,但问题仍然存在。

谢谢。

您是否部署了物理 svc 文件并将其标记绑定到代码?如果您在 iis 站点 bin 中只有一个 dll,但在指定的虚拟路径中没有 SVC 文件,那么您将得到 403,除非您在 web.config 的 serviceActivations 部分中配置 relativeAddress。

<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add relativeAddress="Service1.svc" service="YourService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>

根据评论,这似乎是 WCF 的 IIS 配置问题。 ServiceModel Registration Tool (ServiceModelReg.exe)工具可以运行(或重新运行)来解决这个问题。