【发布时间】:2023-03-21 02:50:01
【问题描述】:
我目前正在使用 VS 2005 在 C# 中编写一个 RESTful WCF 服务。我通过 IIS 托管该服务并且可以浏览到 .svc,但是每当我尝试导航到任何 URI 时,我都会收到 404 错误。如果我运行 wcftestclient(包含在 VS 2008 中),那么我可以看到这些方法,因此我知道该服务正在运行。问题似乎出在实现的 REST 部分。
这是我的 web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyAPI">
<endpoint binding="webHttpBinding" contract="IExternalAPI"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这是合同:
[ServiceContract()]
interface IExternalAPI {
[OperationContract]
[WebGet (BodyStyle=WebMessageBodyStyle.Bare,ResponseFormat=WebMessageFormat.Json,UriTemplate="{APIKey}/Favorites/{userId}")]
string GetFavoritesList(string APIKey, string userId);
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Addresses/{userId}")]
string GetAddressList(string APIKey, string userId);
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Authenticate/{userName}/{password}")]
string Authenticate(string APIKey, string username, string password);
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Checkout/{orderId}/{userId}/{tip}/{addressId}")]
string Checkout(string APIKey, string orderId, string userId, string tip, string addressId);
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/AddToOrder/{templateId}/{userId}")]
string AddFavoriteToOrder(string APIKey, string templateId, string userId);
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Pending/{userId}")]
string GetPendingOrders(string APIKey, string userId);
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "Bob")]
string TestMethod();
}
任何帮助将不胜感激。
【问题讨论】:
-
您使用的是什么软件版本?
-
您要导航到哪个 URI?你能给我们一个样品吗?
-
URI 类似于 localhost/MemberServices/MemberServices.svc/Bob localhost/MemberServices/MemberServices.svc/1234/Favorites/567 我正在运行带有所有服务包、IIS 5.1 和 .NET 3.5 的 VS 2005
标签: c# wcf iis visual-studio-2005