Create AJAX WCF and AJAX
WCF--Windows Communication Foundation , 以下只是2,3两步是重要的。
1.new project (eg “ empty web application”)
2.create a “WCF AJAX-enabled service”
2.1 project in the Solution Explorer window and select Add, then New Item
2.2 Name the service (eg." NewService.svc ") in the Name box and click Add.
3. To Create " ScriptManager" and configure the client to access the service
3.1 add ScriptManager to *.aspx
3.2 Right-click the ScriptManager and select Properties.
Expand the Services collection in the Properties window to open up the ServiceReference Collection Editor window.
Click Add, specify (eg. NewService.svc , it is AJAX Service 's file name ) as the Path referenced, and click OK.
Code:
/>
/>4. done add code to service and *.aspx/*.aspx.cs
4.1 *.aspx.cs can reference service(auto add reference)
4.2 write test "Contract" in NewService.svc
[ OperationContract ]
public double CostOfSandwiches( int quantity)
{ return 1.25 * quantity; }
4.3 *.aspx
code in aspx and *.cs(add label to *.aspx , and code in *.apsx.cs)
protected void Page_Load(object sender, EventArgs e)
{
CostService abc = new CostService ();
Label1.Text = abc.CostOfSandwiches(6).ToString(); }