404尝试执行Web服务时出错

时间:2012-10-16 15:22:47

标签: wcf iis-7.5 http-status-code-404

我有一个我创建的简单Web服务。我正在使用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的相关部分是:

<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服务器(我的盒子本地)。

在客户端应用中,我创建了一个服务引用。当我点击Discover时,它会找到:

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

但是,当我运行我的客户端时,收到以下消息:

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错误。

客户端的.config文件具有以下自动生成的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>

我已经在圈子里走了几个小时,无法弄清楚我已经搞砸了什么,但我肯定做错了。

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

1 个答案:

答案 0 :(得分:1)

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

或者您可以尝试以下适合我的解决方案。添加服务引用时,

  1. 点击“添加服务参考”窗口
  2. 中的“高级...”按钮
  3. 禁用“在引用的程序集中重用类型”。
  4. 然后应该生成你的课程。