简体   繁体   中英

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

I have a WCF WebService that uses JSON format. I can run it in Visual Studio 2013 properly but when i publish it to IIS to run by my machine local ip and a specific port (192.168.1.6:8005) to access it from local network by this address :

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

it is the error :

 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

three files namely : Service1.svc, Web.config and JSONSample.dll are exist in physical path of its IIS Website.

here is my 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>

And a part of 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); 

I read very articles and topics to solve this problem, but the problem still exist.

Thanks.

Per the comments, it appears this was an issue with IIS configuration for WCF. The ServiceModel Registration Tool (ServiceModelReg.exe) tool can be run (or re-run) to resolve this.

Did you deploy the physical svc file with the markup tieing it to the code? If you just have a dll in the iis sites bin but no SVC file at the specified virtual path than you will get a 403 unless you configure the relativeAddress in the web.config's serviceActivations section.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM