2011-11-16 53 views
2

我在網上搜索,但沒有找到任何合適的文章解釋如何使用JavaScript,特別是WebScriptEndpoint使用WCF服務。使用JavaScript使用WebScriptEndpoint消費WCF服務

任何人都可以對此有任何指示嗎?

感謝

+0

_「當你使用[WebScriptEndpoint]正在編寫從ASP.NET AJAX應用程序調用的服務。「_ [Manual](http://msdn.microsoft.com/zh-cn/library/system.servicemodel.description.webscriptendpoint.aspx)。你確定這是你想要的嗎? – CodeCaster

+0

感謝CodeCaster編輯我的問題:) – BreakHead

+0

@CodeCaster我不能使用腳本管理器等,沒有ASP.net。想從我的純HTML5頁面中使用服務 – BreakHead

回答

0

這裏是關於REST服務的好文章:http://msdn.microsoft.com/en-us/magazine/dd315413.aspx

總之,你想用的WebHttpBinding配置的端點。 此端點應該有webHttp行爲啓用:

<services> 
    <service name="TestService"> 
    <endpoint address="test" binding="webHttpBinding" behaviorConfiguration="restBehavior" contract="ITestService"/> 
    </service> 
</services> 

行爲:

<behavior name="restBehavior"> 
    <webHttp/> 
</behavior> 

然後在您的服務接口:

[ServiceContract] 
public interface ITestService 
{ 
    [OperationContract] 
    [WebGet(UriTemplate = "test?p={p}", ResponseFormat = WebMessageFormat.Json)] 
    string Test(string p); 
} 

您可以使用WebGet或WebInvoke屬性(取決於是否你想GET或POST)...