2011-06-21 159 views
3

我寫的方法合同:爲什麼GET'時會出現這個WCF錯誤?

[OperationContract] 
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)] 
    string TestEchoWithTemplate(string s); 

和實現方法:

public string TestEchoWithTemplate(string s) 
    { 
     return "You said " + s; 
    } 

當我瀏覽的網址:

http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/HelloWorld

我收到以下錯誤:

Operation 'TestEchoWithTemplate' in contract 'IVLSContentService' has a UriTemplate that expects a parameter named 'MESSAGE', but there is no input parameter with that name on the operation.

下產生了同樣的錯誤:

http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/MESSAGE=HelloWorld 的http://本地主機:52587/VLSContentService.svc/REST/TestEchoWithTemplate消息=的HelloWorld

我在做什麼錯?

回答

6

定義模板

"TestEchoWithTemplate/{s}" 

因爲你的方法有s,而不是message。或者在您的界面中將名稱更改爲message

[OperationContract] 
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)] 
string TestEchoWithTemplate(string message); 
+0

工作感謝您的幫助 – Exitos

相關問題