[英]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.