0
的獲取工作正常,但通過使用ID或POST的get PUT將返回錯誤404WCF作爲html頁面的數據服務。 jQuery的Ajax功能。
WCF DataService.svc
公共功能GetHealthcare(BYVAL類別ID作爲字符串)作爲vwHealthcare器具IDataService。 GetHealthcare 昏暗nSubject作爲新vwHealthcare
Dim context As DataClasses1DataContext = New DataClasses1DataContext()
'Check if exists
Dim res = From b In context.vwHealthcares Where b.CategoryId = CategoryId
Select b
Dim uList As List(Of vwHealthcare) = res.ToList()
Return res
End Function
IDataService
<WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json, UriTemplate:="GetHealthcareByCategoryId/{CategoryId}")>
<OperationContract()>
Function GetHealthcare(ByVal CategoryId As String) As vwHealthcare
我的客戶端HTML:
// Urls to access the WCF Rest service methods var urlsource ; urlsource = "http://localhost/ehealthservice/DataService.svc/"; var varType; var varUrl; var method; var varData; var varContentType; var varDataType; var varProcessData; //Generic function to call AXMX/WCF Service function CallServiceC() { debugger; var categoryid = getQueryStringValue('CategoryId'); var oData; debugger; $.ajax({ cache: false, type: varType, //GET or POST or PUT or DELETE verb url: varUrl, // Location of the service data: oData, //Data sent to server contentType: varContentType, // content type sent to server crossDomain: true, dataType: varDataType, timeout: 2000, success: function (msg) {//On Successfull service call debugger; // I want to get here return html; } }, error: ServiceFailedC// When Service call fails }); } function ServiceFailedC(result) { debugger; var myJSON = JSON.stringify(result); alert('Service call failed: ' + result.status + '' + result.statusText); varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null; } function GetHealthcareByCategory() { debugger; varType = "POST"; varUrl = urlsource + "GetHealthcareByCategoryId/1"; varContentType = "application/json; charset=utf-8"; varDataType = "jsonp"; varProcessData = false; method = "GetHealthcare"; CallServiceC(); } function getQueryStringValue(key) { debugger; return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); }; $(document).ready( function() { GetHealthcareByCategory(); } );
注: 我已經嘗試了許多方法還是一樣的404錯誤。我也啓用了文件夾的讀/寫權限。本示例遵循Pranya示例,鏈接enter link description here,並且我仍然收到錯誤404請任何開發人員在房子裏。