【问题标题】:RESTful WCF hosting in IISIIS 中的 RESTful WCF 托管
【发布时间】: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();
    }

任何帮助将不胜感激。

【问题讨论】:

标签: c# wcf iis visual-studio-2005


【解决方案1】:

我知道这是在您发帖 4 个月后,但我遇到了类似的情况。我的配置看起来和你的几乎一样,在我添加 endpointBehavior 键之前我遇到了同样的问题。尝试在您的服务端点中指定对您的端点行为的显式引用。也许这会有所帮助。

<service behaviorConfiguration="ServiceBehavior" name="MyAPI">
    <endpoint binding="webHttpBinding" behaviorConfiguration="ServiceBehavior" contract="IExternalAPI"/>
    <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/>
</service>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 2016-06-06
    • 1970-01-01
    • 2022-12-13
    相关资源
    最近更新 更多