简体   繁体   中英

Server Error in '/' Application. The resource cannot be found. (404) when deploying WCF service to Azure App Service

I am creating a WCF service to store some data in a Xamarin.Forms application I am making. I have deployed this service to an Azure App Service. I am getting the following error when navigating to the URL:

Server Error in '/' 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: /EventWCFService.svc

Code-behind of the WCF service:

 public class EventWCFService : IEventWCFService
    {
        private static IEventService _eventService = new EventService(new EventRepository());
        public void AddEvent(Event @event)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(@event.EventTitle) || @event == null)
                {
                    throw new FaultException("Event name is required");
                }

                _eventService.AddEvent(@event);
            }
            catch (Exception exception)
            {
                throw new FaultException($"Whoops... Something has gone wrong {exception.Message}");
            }
        }
        public IList<Event> GetAllEvents()
        {
            return _eventService.GetAllEvents();
        }
    }

My WCF project also contains repositories and services:

在此处输入图像描述

IEventWCFService:

 [ServiceContract]
    public interface IEventWCFService
    {
        [OperationContract]
        IList<Event> GetAllEvents();
        [OperationContract]
        void AddEvent(Event @event);
    }

Web.Config:

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.8" />
    <httpRuntime targetFramework="4.8"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- 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>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        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"/>
  </system.webServer>

</configuration>

Things I've tried:

  1. First of all I tried to go to the properties and create a virtual directory - that did not work or solve the problem.

  2. I tried to set the 'Specific page' to blank - it still did not solve the problem.

  3. I tried to create a new app service - and I still got the problem.

I am quite new to WCF - so apologies if this may be a rookie mistake. I am a following a Pluralsight course and I was getting along quite well until the Azure deployment part.

I solved this problem by creating and deploying a new Azure App Service directly from the Azure portal rather than from Visual Studio itself. Then - I deployed the WCF service directly from the existing app service that I had just created.

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