0

I am very new to working with web services and a novice in C# as well so I apologize for asking such a simple question. I am working on taking this xml request and converting it valid C# code. I believe this will improve the structure of my request and ensure it sends back a valid response each time. Could someone possibly assist me in moving forward with this? Any help is greatly appreciated.

http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=<?xml version ="1.0" encoding ="UTF-8" ?>
<TrackRequest USERID= "xxxxxxxxx">
<TrackID ID = "xxxxx1"></TrackID>
<TrackID ID = "xxxxx2"></TrackID>
<TrackID ID = "xxxxx3"></TrackID>
</TrackRequest>
  • Your question title says that you're trying to take XML/SOAP requests and convert them to C# code. However, your question (as far as I can tell) says that you're trying to do the reverse. What exactly is your question? – Andrew Fan Dec 05 '18 at 15:54
  • I apologize, yes I do want to turn a xml request into C# code, what I attached was what I thought was needed to achieve this. here is the request I am trying to get into C# http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML= – atlmkecode Dec 05 '18 at 16:02
  • You should edit your question to make that clear, since you currently state that "I am working on taking this c# code and converting it to an XML document using XMLDocument." which suggests something other than what you clarified in your comment. This will help other people understand your question. – Andrew Fan Dec 05 '18 at 16:05
  • edited, again apologies for the miscommunication – atlmkecode Dec 05 '18 at 16:10
  • There are command line tools to convert c# classes to and from XML. You can code your own to dynamically serlialize an object to a string in XML format, using classes such as XmlSerializer. With SOAP services, serialization normally occurs automatically through the framework. You define contracts and the DataContractSerializer performs the transformation. Being new to Web Services, it might be good practice to familiarize yourself with SOAP, but these are largely, legacy services, replaced by JSON, REST services. That is, RESTful services using JSON instead of XML. – Antony Booth Dec 05 '18 at 16:10
  • Xsd.exe is a command line tool that takes an XML schema (XSD) and generates C#, VB classes etc. You can use online tools like this: http://xmlgrid.net/xml2xsd.html to convert XML to XSD. XSD.exe is useful if you are consuming another service SOAP response and want to map it to classes, without just adding a reference to the SOAP service in your .net project, where those classes are auto-generated proxies. Examples of converting an object to XML may be found here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/examples-of-xml-serialization. – Antony Booth Dec 05 '18 at 16:18
  • If you are trying to consume some SOAP XML from a web service with a WSDL you can auto-generate a client, see [Possible to autogenerate to code using WSDL in Visual Studio](https://stackoverflow.com/q/13061172) and [How to make a SOAP/WSDL client in C#?](https://stackoverflow.com/q/2772708). – dbc Dec 05 '18 at 18:45

0 Answers0