2
新配置任何服務器端...先感謝您的幫助!WCF休息API - [WebGet]工作,但沒有找到[WebInvoke(... GET ...)]端點
我想在VisualStudio2008/.NET 3.5中獲得一個簡單的HelloWorld REST API;最終我將使用它來將CRUD測試數據/結果從本地無線局域網上運行的各種移動設備發送回服務器。
我發現了一些其他問題,誰的答案改變我的app.config的相關零部件,但沒有一個似乎適用於這一具體問題(和反覆試驗還沒有產生任何結果)
- 我的WebGet查詢成功返回我的數據。
- 我WebInvoke API GET請求返回錯誤 「端點未找到」
這裏是我的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;'
}
這裏是我的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>
我在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
連接
在我的瀏覽器上。
- '測試' 回報 'foobar的'
- 'Test2的' 回報 'foobar的='(不管是什麼 '?PARAM' 或 '/參數' 我添加到URL
- 「的尾部XMLDATA 「給出了一個錯誤‘端點未找到’(在瀏覽器中顯示爲HTML)
感謝很多
您是否嘗試過http:// localhost/foo/bar/xml/123?那樣有用嗎? –
@NicoleDesRosiers看起來就是這樣 - 我的查詢語法是錯誤的:) 請提交一個答案,以便我可以信任你。 – mike
請不要使用'[WebInvoke(Method =「GET」)]'。 'WebGet'起作用,你輸入較少,它可能會給你一些GET(理論上冪等)請求的特徵,而[WebInvoke]不會。 – carlosfigueira