Data Integrity in Web Services (轉二)

來源:互聯網
上載者:User
services|web 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.

相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。