我创建了一个简单的 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 服务器(我的盒子本地)。
在客户端应用程序中,我创建了一个服务引用。当我单击发现时,它会发现:
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 应用程序。