In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the methods of using polymorphism in Web Services. I hope you will get something after reading this article. Let's discuss it together.
In Web Services methods, a specific type of parameter is often used, which is usually a data object. ASP.NET Web Services can implement the use of polymorphism in Web Services methods by declaring XmlIncludeAttribute.
XmlIncludeAttribute allows XmlSerializer to recognize types when serializing fire deserialized objects. When you apply XmlIncludeAttribute, you need to specify the Type of the derived class. After XmlSerializer serializes objects that contain both base and derived classes, it can recognize both object types.
First define the base class Vehicle and the derived class Car:
Public abstract class Vehicle {public string LicenseNumber {get;set;} public DateTime MakeTime {get;set;}} public class Car: Vehicle {public int DoorNum {get;set;}}
Define the Web Method of AddVehicle, declaring that XmlInclude needs to add a reference to the namespace System.Xml.Serialization:
[WebMethod] [XmlInclude (typeof (Car))] public void AddVehicle (Vehicle vehicle) {}
View the generated wsdl,wsdl that uses the base property of extension to describe the Car inheritance Vechicle.
If you view the Reference.cs file generated by referencing Web Services, the Vehicle class will have the declaration of XmlIncludeAttribute:
[System.Xml.Serialization.XmlIncludeAttribute (typeof (Car))] [System.CodeDom.Compiler.GeneratedCodeAttribute ("System.Xml", "4.0.30319.1")] [System.SerializableAttribute ()] [System.Diagnostics.DebuggerStepThroughAttribute ()] [System.ComponentModel.DesignerCategoryAttribute ("code")] [System.Xml.Serialization.XmlTypeAttribute (Namespace= "http://tempuri.org/")] public abstract partial class Vehicle: object")
Client test code:
Static void Main (string [] args) {localhost.WebService1SoapClient c = new localhost.WebService1SoapClient (); localhost.Car car = new localhost.Car () {LicenseNumber= "0001", MakeTime=DateTime.Now, DoorNum=2 c.AddVehicle (car);}
You can view the passed parameters in the AddVehicle method of Web Services:
Web Services can support polymorphism, but it can only be used when serializable code is generated when Web Services can be referenced directly, and it still takes a lot of effort to use it on other clients.
After reading this article, I believe you have a certain understanding of "what are the methods of using polymorphism in Web Services". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.