简体   繁体   English

WCF rest api-[WebGet]工作,但未找到[WebInvoke(…GET…)]的端点

[英]WCF rest api - [WebGet] working, but endpoint not found for [WebInvoke(…GET…)]

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; 我试图在VisualStudio2008 / .NET 3.5中获得一个简单的HelloWorld REST API; 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. 最终,我将使用它对本地无线局域网上运行的各种移动设备进行CRUD测试数据/结果返回到服务器。

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) 我发现了许多其他问题,谁的答案更改了我app.config的相关部分,但似乎没有一个适用于此特定问题(反复试验未产生任何结果)

  • My WebGet query returns my data successfully. 我的WebGet查询成功返回了我的数据。
  • The Get request with my WebInvoke api returns an error "Endpoint not found" 我的WebInvoke api的Get请求返回错误“找不到端点”

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 这是我的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 我正在visualstudio中通过f5运行(我认为这意味着我没有任何可担心的.svc / IIS东西?),并尝试通过

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' '测试'返回'foobar'
  • 'Test2' returns 'foobar=' (no matter what '?param' or '/param' I add to the tail of the URL 'Test2'返回'foobar ='(无论我添加到URL尾部的是什么'?param'或'/ param'
  • 'XMLData' gives an error 'Endpoint not found' (displayed as html in my browser) “ XMLData”给出错误“找不到端点”(在我的浏览器中显示为html)

Thanks much 非常感谢

您已经覆盖了要在xml / {id}上访问的XMLData端点,但是您将其称为XMLData / {id}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM