2009-06-08 9 views
0

Ich schreibe gerade einen RESTful WCF-Dienst in C# mit VS 2005. Ich hostiere den Dienst über IIS und kann zur .svc wechseln, aber immer wenn ich versuche, zu einem der URIs zu gelangen ein 404 Fehler. Wenn ich den (in VS 2008 enthaltenen) wcftestclient ausführe, kann ich die Methoden sehen, also weiß ich, dass der Dienst funktioniert. Das Problem scheint mit dem REST-Teil der Implementierung zu sein.RESTful WCF-Hosting in IIS

Das ist mein 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> 

Dies ist der Vertrag:

würde
[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(); 
    } 

Jede Hilfe sehr geschätzt.

+0

Welche Softwareversionen verwenden Sie? –

+0

Welcher URI navigieren Sie? Können Sie uns eine Probe geben? –

+0

Die URIs sind Dinge wie http: //localhost/MemberServices/MemberServices.svc/Bob http: //localhost/MemberServices/MemberServices.svc/1234/Favorites/567 Ich bin VS 2005 mit allen Service Packs ausgeführt wird , IIS 5.1, und .NET 3.5 –

Antwort

2

Ich weiß, das ist 4 Monate nach Ihrer Post, aber ich bin in einer ähnlichen Situation beschäftigt. Meine Konfiguration sieht fast identisch mit Ihrer aus, und ich hatte das gleiche Problem, bis ich den endpointBehavior-Schlüssel hinzugefügt habe. Versuchen Sie, in Ihrem Dienstendpunkt einen expliziten Verweis auf Ihr Endpunktverhalten anzugeben. Vielleicht wird das helfen.

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