Apr 12, 2011, 11:41 AM
[CLOSED] REST with WCF - part 2
My REST-based WCF application using Ext.NET 1.0 works fine for retrieving data, but now I'm add functionality to update data, so here's the page markup:
The page works fine for retrieving data but if I uncomment the UpdatePerson method in the interface, I get an error when the data is loaded saying that
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrudRest.aspx.cs" Inherits="TWA.Forms.CrudRest" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:Store runat="server" id="StoreRestful" AutoLoad="true" Restful="true">
<BaseParams>
<ext:Parameter Name="start" Value="={0}" />
</BaseParams>
<Proxy>
<ext:HttpProxy Json="true" Url="~/Service/Candidate.svc">
</ext:HttpProxy>
</Proxy>
<Reader>
<ext:JsonReader IDProperty="PersonId" Root="Data" TotalProperty="Count" SuccessProperty="Success">
<Fields>
<ext:RecordField Name="PersonId" Type="Int"/>
<ext:RecordField Name="FirstName" />
<ext:RecordField Name="Surname" />
<ext:RecordField Name="Initials" />
<ext:RecordField Name="JobTitle" />
<ext:RecordField Name="DateOfBirth" Type="Date" DateFormat="M$" />
</Fields>
</ext:JsonReader>
</Reader>
<Listeners>
<BeforeLoad Handler="debugger;this.proxy.setApi('read','http://lonmw65502.fm.rbsgrp.net/TWA/Service/candidate.svc/' + options.params.start);" />
<BeforeSave Handler="debugger;this.proxy.setApi('update','http://lonmw65502.fm.rbsgrp.net/TWA/Service/candidate.svc/' + options.params.start);" />
<DataChanged Handler="debugger;var rec=this.getAt(0)||{};#{FormPanel2}.getForm().loadRecord(rec);#{FormPanel2}.clearInvalid();" />
</Listeners>
</ext:Store>
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<ext:Viewport ID="Viewport1" runat="server" Layout="form" StyleSpec="margin:10px">
<Items>
<ext:FormPanel ID="FormPanel2" runat="server" ButtonAlign="Right" Height="230" Padding="5"
Title="Candidates (RESTful)" Width="500" LabelSeparator="">
<Items>
<ext:TextField ID="RestFirstName" DataIndex="FirstName" runat="server" AnchorHorizontal="100%" FieldLabel="Name">
</ext:TextField>
<ext:TextField ID="RestInitials" DataIndex="Initials" runat="server" AnchorHorizontal="100%" FieldLabel="Initials">
</ext:TextField>
<ext:TextField ID="RestSurname" DataIndex="Surname" runat="server" AnchorHorizontal="100%" FieldLabel="Surname">
</ext:TextField>
<ext:TextField ID="RestJobTitle" DataIndex="JobTitle" runat="server" AnchorHorizontal="100%" FieldLabel="Job title">
</ext:TextField>
<ext:DateField ID="RestDOB" DataIndex="DateOfBirth" runat="server" AnchorHorizontal="100%" FieldLabel="Date of birth" >
</ext:DateField>
</Items>
<Buttons>
<ext:Button ID="Button2" runat="server" Icon="Disk" Text="Submit">
<Listeners>
<Click Handler="
debugger;var start=#{StoreRestful}.getAt(0).id,rec=#{FormPanel2}.form.getFieldValues();#{StoreRestful}.loadData(rec);#{StoreRestful}.save();
" />
</Listeners>
</ext:Button>
</Buttons>
<BottomBar>
<ext:PagingToolbar ID="PagingToolbar2" runat="server" StoreID="StoreRestful" PageSize="1" DisplayInfo="True" LastText="Last record" NextText="Next record" PrevText="Previous record" FirstText="First record" DisplayMsg="Displaying {0} of {2}" BeforePageText="Record">
<Listeners>
</Listeners>
</ext:PagingToolbar>
</BottomBar>
</ext:FormPanel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
There is no custom code-behind but the service implementation is: [ServiceContract]
public interface ICandidate
{
[OperationContract]
[WebGet(UriTemplate="/{index}",
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json)]
Common.RestResponse<Person> GetPersonByIndex(string index);
/*[OperationContract]
[WebInvoke(Method="PUT", RequestFormat=WebMessageFormat.Json, UriTemplate="/{index}")]
void UpdatePerson(Person person);*/
}
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class Candidate : ICandidate
{
public Common.RestResponse<Person> GetPersonByIndex(string index)
{
Common.RestResponse<Person> result = new TWA.Common.RestResponse<Person>();
int Index = 0;
if (Int32.TryParse(index, out Index))
{
List<Person> list = PersonService.GetPersonList(true, true, true);
if (list.Count > Index)
{
result.Success = true;
result.Count = list.Count;
result.Data = list[Index];
}
}
return result;
}
public void UpdatePerson(Person person)
{
RBS.RegRisk.ApprovedPersons.WebUI._Common.Classes.Util.UpdateAuditInfo(person);
PersonService.SavePerson(person);
}
}
That defines the service contract interface and the implementation.The page works fine for retrieving data but if I uncomment the UpdatePerson method in the interface, I get an error when the data is loaded saying that
Operation 'UpdatePerson' in contract 'ICandidate' has a UriTemplate that expects a parameter named 'INDEX',
but there is no input parameter with that name on the operation.
Why is this happening? I haven't called the REST update/PUT associated method so I'm wondering why that error occurs when calling the service to get the data.
Last edited by Daniil; Apr 25, 2011 at 7:54 AM.
Reason: [CLOSED]