azamsharp
azamsharp

Reputation: 20094

WCF Restful Services URI Template Not Working

I am creating a simple WCF Restful service. Currently when I browse to: localhost/AzamSharpService.svc it shows me the web services default page where I can examine WSDL.

I want to browse to localhost/AzamSharpService.svc/LatestArticles and get the json from the GetLatestArticles method. Currently, when the browse to the /LatestArticles url it says page not found.

The implementation is shown below:

 [ServiceContract]
    public interface IAzamSharpService
    {
        [OperationContract]
        [WebGet(BodyStyle  = WebMessageBodyStyle.Bare, RequestFormat =WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json, UriTemplate = "/LatestArticles")]
        List<ArticleContract> GetArticles();
    }

 public class AzamSharpService : IAzamSharpService
    {
        public List<ArticleContract> GetArticles()
        {
            var articles = new List<ArticleContract>()
                               {
                                   new ArticleContract() {Title = "iOS"}, 
                                   new ArticleContract() { Title="Android"},
                                   new ArticleContract() { Title = "Windows 7"}

                               };
            return articles; 
        }
    }

The configuration is shown below:

 <system.serviceModel>

      <services>
        <service name="AzamSharpNewLook.AzamSharpService">
          <endpoint address="AzamSharpService.svc"
                    binding="webHttpBinding"
                    contract="AzamSharpNewLook.IAzamSharpService"
                    behaviorConfiguration="webby"/>

            </service>
      </services>
        <behaviors>

          <endpointBehaviors>
            <behavior name="webby">
              <webHttp/>
            </behavior>
          </endpointBehaviors>

            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
    </system.serviceModel>

Upvotes: 0

Views: 2867

Answers (1)

Hcabnettek
Hcabnettek

Reputation: 12928

A couple of things to try... set endpoint address to empty string...in the webHttp node try enabling help... and you should be able to navigate to localhost/AzamSharpService.svc/help and get more info. Lastly I would use fiddler and construct a get request to the appropriate address, then just check the response and you should have what you need. Hope this helps...

Upvotes: 1

Related Questions