只找Java工作

胡说—八道。胡言-乱语。 但不骗你
正文

别让WCF吓着了-Create AJAX WCF

(2011-10-25 12:55:28) 下一个


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: < asp : ScriptManager ID ="ScriptManager1" runat ="server">
< Services >
< asp : ServiceReference Path ="NewService.svc " />

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(); }
 

[ 打印 ]
阅读 ()评论 (0)
评论
目前还没有任何评论
登录后才可评论.