[英]WCF Restful service endpoint in Visual Studio giving 404
我一直在努力为使用Visual Studio创建的简单Web服务标识正确的端点,但是我一直遇到404错误。 之前,我只用C#做过另一项Web服务,而在遇到相同错误之前,我一直认为自己终于弄清楚了语法。
web.config:
<services>
<service name="LDAPws.LDAPService" behaviorConfiguration="LDAPServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="LDAPws.LDAPServiceInterface" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
webServiceContract.cs:
namespace LDAPws
{
[ServiceContract(Name = "LDAPService")]
public interface LDAPServiceInterface
{
//GET operation
[OperationContract]
[FaultContract(typeof(GetResourcesFaultContract))]
[WebGet(UriTemplate = "/echo", ResponseFormat = WebMessageFormat.Json)]
string sayHello();
webServiceLib.cs
namespace LDAPws
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LDAPService : LDAPServiceInterface
{
public string sayHello()
{
return "Hello";
}
网址:
http://localhost:8585/ldapws/ldapservice/echo
我无法弄清楚自己在做什么。 我的目标是Dot Net Framework 4.0并在Visual Studio中托管。 我以为默认的URI是namespace.webservicename / parameters,但这对我不起作用。 在web.config中添加基址和地址似乎也无济于事。
任何帮助,将不胜感激。
我发现了问题的根源:
我错过了添加global.asax文件并将服务添加到项目的过程。 即
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("LDAPws", new WebServiceHostFactory(), typeof(LDAPService)));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.