首页 > 开发 > 综合 > 正文

Data Integrity in Web Services (转二)

2024-07-21 02:25:02
字体:
来源:转载
供稿:网友
although you can create any client you desire for the web service, in this example i have chosen to create a windows application. to do so, simply go to file->new project and choose windows application. drag and drop the items on the form to look something like the figure below.


now choose project->add web referance and in the bottom left of this dialog box choose "web referances on loacal web server". choose the web service we created in step one, then click on ok.

below is the event handler code for the two buttons of the application. the rest of the code required for the application should be autogenerated by the form builder. also note you'll need to include the namespace of the web service in order to use the wrapper objects. it should look something like "using windowsapplication1.localhost;", but you can find out the exact namespace from the class view->localhost->personservice. look at the top of this code file and see what namespace vs.net gave this wrapper.


private void getterbutton_click(object sender, system.eventargs e)
{
    persondata pd = ps.getpersondata();
    firstnamefield.text = pd.firstname;
    lastnamefield.text = pd.lastname;
    yearsexperiencefield.text = ""+ pd.yearsexperience;
}

private void setterbutton_click(object sender, system.eventargs e)
{
    persondata pd = new persondata();
    pd.firstname = firstnamefield.text;
    pd.lastname = lastnamefield.text;
    pd.yearsexperience = int32.parse(yearsexperiencefield.text);
    try
    {
        ps.setpersondata(pd);
        messagebox.show("person set");
    }
    catch(exception exx) { messagebox.show("error setting data:"+ exx); }
}



to drive the point home as to what vs.net is doing with the web service, double click on the persondata struct in the classview of your application.


taking a look around inside the class viewer is an excellent way to find out exactly what kinds of wrappers vs.net is creating for differant things you might be doing and will generally give you an excellent idea of what to expect from your remote objects.


web services are one of the hottest technologies going right now but there are a number of pitfalls that any programmer must be aware of. data integrity is important for any object's proper functioning and must be assured or it could corroupt a larger program and generate a very difficult to trace error. by using the techniques in this article you can keep your objects safe and your data assured.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表