简体   繁体   中英

Web Service 404 Error

I have created a web service that returns JSON data. It works correctly when accessing through my local host.

http://localhost:6553/Service1.svc/GetViewData

but when I deploy and try to run on my production server I get the following error:

Server Error in '/JSONWebService' Application. The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /JSONWebService/Service1.svc/GetViewData

If I remove the /GetViewData from the URL I get the following message:

Server Error in '/JSONWebService' Application. The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /JSONWebService/Service1.svc/GetViewData

If I remove the /GetViewData from the URL I get the following message:

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://ac.gtest.oh.edu/JSONWebService/Service1.svc?wsdl

Here is my web config:

<?xml version="1.0"?>
<configuration>

<connectionStrings>
<add name="Web_TransferConnectionString" connectionString="Data Source=dart;Initial Catalog=Web_Transfer;Integrated Security=True"
  providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<services>
  <service name="JSONWebService.Service1">
    <endpoint address="../Service1.svc" binding="webHttpBinding" contract="JSONWebService.IService1" behaviorConfiguration="webBehaviour" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
 <!-- <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
   <baseAddressPrefixFilters>
     <add prefix="http://www.JSONWebService.com/"/>
   </baseAddressPrefixFilters>
 </serviceHostingEnvironment> -->
</system.serviceModel>
<system.webServer>
<!--  <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type, Accept"/>
  </customHeaders>
 </httpProtocol> -->
 <modules runAllManagedModulesForAllRequests="true">
  <remove name="ApplicationInsightsWebTracking"/>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
    preCondition="managedHandler"/>
 </modules>
   <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
 <directoryBrowse enabled="true"/>
 <validation validateIntegratedModeConfiguration="false"/>

IService1.cs file:

 public interface IService1
{

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetViewData")]
    //string GetData(string value);
    List<wsUpcomingDissertationsView> GetViewData();

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: Add your service operations here
}

Service1.svc.cs

 public class Service1 : IService1
{
    //public string GetData(string value)
    //{
    //    return string.Format("You entered: {0}", value);
    //}

    public List<wsUpcomingDissertationsView> GetViewData()
    {

        Upcoming_Dissertations_ViewDataContext dc = new Upcoming_Dissertations_ViewDataContext();
        List<wsUpcomingDissertationsView> results = new List<wsUpcomingDissertationsView>();

        foreach (Upcoming_Dissertations_View UDV in dc.Upcoming_Dissertations_Views)
        {
            results.Add(new wsUpcomingDissertationsView()
            {
                First_Name = UDV.FIRST_NAME,
                Last_Name = UDV.LAST_NAME,
                exam_oral_date = UDV.exam_oral_date,
                Expr1 = UDV.Expr1,

            });
        }

        return results;
    }

UPDATE: I got it to work after hours of trial and error. I made some modifications:

<system.serviceModel>
<services>
  <service name="JSONWebService.Service1">
    <endpoint address="" binding="webHttpBinding" contract="JSONWebService.IService1" bindingConfiguration="webBinding" behaviorConfiguration="webBehaviour"/>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webBinding">
      <security mode="Transport">
      </security>
    </binding>
  </webHttpBinding>
</bindings>

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