문제

New to configuring anything server side ... thanks in advance for your help!

I am trying to get a simple HelloWorld REST api working in VisualStudio2008 / .NET 3.5; eventually I'll be using it to CRUD test data/results back to the server from a variety of mobile devices running on a local wireless lan.

I've found a number of other questions who's answers change related parts of my app.config, but none seem to apply to this specific issue (and trial and error hasn't yielded any results)

  • My WebGet query returns my data successfully.
  • The Get request with my WebInvoke api returns an error "Endpoint not found"

Here is my ServiceContract:

[ServiceContract]
public interface IRestService
{
    [OperationContract]
    [WebInvoke(
        Method = "GET",
        ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "xml/{id}")]
    string XMLData(string id);  //Implemented as 'return "you requested " + id;'

    [OperationContract]
    [WebGet]
    string Test();              //Implemented as 'return "foobar";'

    [OperationContract]
    [WebGet]
    string Test2(string foo);   //Implemented as 'return "foobar=" + foo;'
}

And here is my app.config

<services>
  <service name="MyRestService.IRestServiceImpl" behaviorConfiguration="MyServiceBehavior">

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/foo/bar"/>
      </baseAddresses>
    </host>

    <endpoint address ="" binding="webHttpBinding" contract="MyRestService.IRestService" behaviorConfiguration="myRestBehavior" />

  </service>
</services>

<behaviors>

  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>

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

</behaviors>

I'm running via f5 in visualstudio (which I think means I don't have any .svc/IIS stuff to worry about?), and attempting to connect via

http://localhost/foo/bar/Test
http://localhost/foo/bar/Test2   (  /ParamIgnored if I add one  )
http://localhost/foo/bar/XMLData/123

on my browser.

  • 'Test' returns 'foobar'
  • 'Test2' returns 'foobar=' (no matter what '?param' or '/param' I add to the tail of the URL
  • 'XMLData' gives an error 'Endpoint not found' (displayed as html in my browser)

Thanks much

도움이 되었습니까?

해결책

You've overridden the XMLData endpoint to be accessed on xml/{id}, but you're calling it as XMLData/{id}.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top