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

时间:2015-05-21 15:09:22

标签: c# asp.net web-services wcf iis

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

 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); 

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

感谢。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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