简体   繁体   中英

Create Client of Web Service of C# API

I have created a web service in C# in which I have used a C# entity class that is passed to web service as input by serializing this class and in web service I have deserialize it my web method here is my Serializing code

string xmlText;
var msg = new System.Xml.Serialization.XmlSerializer(obj.GetType());
var ms = new MemoryStream();
using (var xmlTextWriter = new XmlTextWriter(ms, Encoding.ASCII) { Formatting = Formatting.Indented })
{
    msg.Serialize(xmlTextWriter, obj);
    ms = (MemoryStream)xmlTextWriter.BaseStream;
    xmlText = new UTF8Encoding().GetString(ms.ToArray());
    ms.Dispose();
}
return xmlText;

I get XML of this class and I pass it to my web method and I just deserialize it and use this class. Now I want to expose this web method to all clients. The client can be Java, PHP or any other programming language. How will I provide this Class to those clients? I have searched on google there I find create wsdl file. How to convert my entity class to a wsdl file?

Any help will be highly appreciated. Regards.

I think the best way to go is what you're already doing: serialize your objects into XML or Json and pass these strings to your clients. These clients will then have to recreate the objects back (using specific methods like json_decode for PHP, for example). A WSDL file describes the public methods of a web service. It will help you to create your clients, but it won't help you to serialize and deserialize objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM