2012-10-16 44 views
0

我有一個簡單的Web服務,我已經創建。我正在使用Visual Studio 2012 .NET 4.5。404嘗試執行Web服務時出錯

這裏是服務合同:

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

在客戶端應用程序中,我創建了一個服務引用。當我點擊查看,發現:

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. 

內部異常只是說,它從網上得到了一個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> 

我一直兜兜轉轉幾個小時,不能找出我有glitched了,但肯定我做了一些錯誤的事情。

不確定它很重要,但客戶端是ASP.NET MVC應用程序。

+4

您可以嘗試瀏覽到Web瀏覽器中的服務本身,而無需使用客戶端。如果你沒有看到通常的WCF網頁,你很可能需要在Windows功能中打開WCF HTTP Activation(以及其他一些東西)。 –

+0

在幾個領域肯定會出現一些奇怪的東西。首先,發現獲取了錯誤的URL。實際的URL是:localhost/GEMS.Core.WCFService.MenuService.svc 當我生成服務引用時,它不創建類。但是,如果我創建一個簡單的控制檯應用程序並讓它創建服務引用,那麼運行正常(給出上面的正確URL)。我不是100%肯定的,但它看起來像Newtonsoft.json可能會導致一些魚腥味。 – Pete

+0

仍然試圖讓一切正常,但到目前爲止,第一步是在另一個應用程序中創建服務客戶端,然後將其複製到我的真實應用程序並更改名稱空間引用。看起來可能是一個VS.NET問題。 – Pete

回答

1

由於皮特解釋Newtonsoft.json.dll導致客戶端不生成服務代碼。您可以刪除該DLL,然後再次添加服務引用。

或者你可以嘗試以下解決方案,爲我工作。窗口

  • 禁用「重用類型的引用程序」 - 當您在「添加服務引用」的「高級...」按鈕添加一個服務引用,

    1. 點擊。

    然後你的類應該被生成。

  • 相關問題