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应用程序。
您可以尝试浏览到Web浏览器中的服务本身,而无需使用客户端。如果你没有看到通常的WCF网页,你很可能需要在Windows功能中打开WCF HTTP Activation(以及其他一些东西)。 –
在几个领域肯定会出现一些奇怪的东西。首先,发现获取了错误的URL。实际的URL是:localhost/GEMS.Core.WCFService.MenuService.svc 当我生成服务引用时,它不创建类。但是,如果我创建一个简单的控制台应用程序并让它创建服务引用,那么运行正常(给出上面的正确URL)。我不是100%肯定的,但它看起来像Newtonsoft.json可能会导致一些鱼腥味。 – Pete
仍然试图让一切正常,但到目前为止,第一步是在另一个应用程序中创建服务客户端,然后将其复制到我的真实应用程序并更改名称空间引用。看起来可能是一个VS.NET问题。 – Pete