Pete
Pete

Reputation: 6743

404 Error when trying to execute web service

I have a simple web service I have created. I'm using Visual Studio 2012 .NET 4.5.

Here is the service contract:

using System.Runtime.Serialization;
using System.ServiceModel;

namespace GEMS.Core.WCFService
{
    [ServiceContract]
    public interface IMenuService
    {
        [OperationContract]
        void AddMenuItem(string menuId, string parentId, string title, string description, string url);
        [OperationContract]
        void UpdateMenuItem(string menuId, string parentId, string title, string description, string url);
        [OperationContract]
        void DeleteMenuItem(string menuId);
        [OperationContract]
        MenuEntry[] GetAllMenuItems();
    }

    [DataContract]
    public class MenuEntry
    {
        [DataMember]
        public string MenuId { get; internal set; }
        [DataMember]
        public string ParentId { get; internal set; }
        [DataMember]
        public string Title { get; internal set; }
        [DataMember]
        public string Description { get; internal set; }
        [DataMember]
        public string Url { get; internal set; }
    }
}

The relevant portion of the app.config is:

<system.serviceModel>
  <services>
    <service name="GEMS.Core.WCFService.MenuService">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8020/GEMS.Core.WCFService/MenuService/" />
        </baseAddresses>
      </host>
      <endpoint address="" binding="basicHttpBinding" contract="GEMS.Core.WCFService.IMenuService" >
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

I publish it to my IIS server (local to my box).

In the client app, I create a service reference. When I click Discover, it finds:

http://localhost:8020/GEMS.Core.WCFService/MenuService/mex

When I run my client, however, I get the following message:

There was no endpoint listening at:
http://localhost:8020/GEMS.Core.WCFService/MenuService/ that could
accept the message. This is often caused by an incorrect address or
SOAP action. See InnerException, if present, for more details.

The inner exception merely says that it got a 404 error from the web server.

The client's .config file has the following auto-generated xml:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IMenuService" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8020/GEMS.Core.WCFService/MenuService/"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMenuService"
      contract="WCF_MenuService.IMenuService" name="BasicHttpBinding_IMenuService" />
  </client>
 </system.serviceModel>

I've been going around in circles for hours and can't figure out what I've got glitched up, but surely I've done somethign wrong.

Not sure that it matters, but the client is an ASP.NET MVC app.

Upvotes: 0

Views: 7524

Answers (1)

Rik van den Berg
Rik van den Berg

Reputation: 2839

As Pete explained Newtonsoft.json.dll causes client to not generate the service code. You can either delete the dll and then add the service reference again.

Or you can do try following solution that worked for me. When you add a service reference,

  1. Click on the 'Advanced...' button in the 'Add service reference' - window
  2. Disable 'Reuse types in referenced assemblies'.

Then your classes should be generated.

Upvotes: 1

Related Questions