当前位置:编程学习 > C#/ASP.NET >>

Data Integrity in Web Services (转一)

Abstract
Web Services bring with them great possibilities and with these possibilities are some pitfalls. One such pitfall is passing complex data types to and from Web Services without losing data integrity. The clearest thing to keep in mind when passing objects to Web Services is the data is passed for your object's fields, but the code is not.
What happens when I have an object that my web service passes as a return value?
WSDL does some magic when a programmer creates a referance to your web service. Visual Studio.NET creates wrapper objects around foreign data types.
The struct you create inside your Web Service looks like this:
public    struct PersonData
{
    private int yearsExperience;
    public int YearsExperience
    {
        get { return yearsExperience; }
        set
        {
       if(value<2) { throw new Exception("You're unemployable!"); }
       yearsExperience = value;
        }
    }
    public String FirstName;
    public String LastName;
}

...Which then gets translated into WSDL which looks like this:
<s:complexType name="PersonData">
    <s:sequence>
补充:asp.net教程,WebService 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,