尝试执行Web服务时出现404错误 [英] 404 Error when trying to execute web service

查看:256
本文介绍了尝试执行Web服务时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个简单的Web服务.我正在使用Visual Studio 2012 .NET 4.5.

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

这是服务合同:

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

app.config的相关部分是:

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>

我将其发布到我的IIS服务器(在我的盒子本地).

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.

内部异常仅表示它从Web服务器收到404错误.

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

客户端的.config文件具有以下自动生成的xml:

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.

不确定是否重要,但是客户端是ASP.NET MVC应用.

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

推荐答案

正如Pete解释的那样,Newtonsoft.json.dll导致客户端无法生成服务代码.您可以删除dll,然后再次添加服务引用.

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. 单击添加服务参考"-窗口中的高级..."按钮
  2. 禁用在引用的程序集中重用类型".

然后应该生成您的类.

这篇关于尝试执行Web服务时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆