First thing you need to do is get the schemas
dos
XML return sending, ie the files Registro.xsd
, ConsultaLote.xsd
and RegistroAdmitido.xsd
. They must have a structure similar to the xsd
example below.:
shiporder.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
So open your Developer Command Propmt for VS...
and manage the classes using the xsd.exe
. Remembering that this command should be executed in the same directory as your schematics.
xsd.exe shiporder.xsd /classes /namespace:ImportXsd
with this, a class such as the following will be generated.:
namespace ImportXsd {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class shiporder {
private string orderpersonField;
private shiporderShipto shiptoField;
private shiporderItem[] itemField;
private string orderidField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string orderperson {
get {
return this.orderpersonField;
}
set {
this.orderpersonField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public shiporderShipto shipto {
get {
return this.shiptoField;
}
set {
this.shiptoField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public shiporderItem[] item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string orderid {
get {
return this.orderidField;
}
set {
this.orderidField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class shiporderShipto {
private string nameField;
private string addressField;
private string cityField;
private string countryField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string address {
get {
return this.addressField;
}
set {
this.addressField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string city {
get {
return this.cityField;
}
set {
this.cityField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string country {
get {
return this.countryField;
}
set {
this.countryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class shiporderItem {
private string titleField;
private string noteField;
private string quantityField;
private decimal priceField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string title {
get {
return this.titleField;
}
set {
this.titleField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string note {
get {
return this.noteField;
}
set {
this.noteField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="positiveInteger")]
public string quantity {
get {
return this.quantityField;
}
set {
this.quantityField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public decimal price {
get {
return this.priceField;
}
set {
this.priceField = value;
}
}
}
}
below follows an example of how serializar
and deserializar
this class of and for a XML
.:
var order = new ImportXsd.shiporder();
order.orderid = "ordemServico";
order.orderperson = "destinatario";
order.shipto = new ImportXsd.shiporderShipto
{
address = "endereço",
city = "cidade",
country = "pais",
name = "nome"
};
order.item = new ImportXsd.shiporderItem[] {
new ImportXsd.shiporderItem {
note = "nota 001",
price = 100,
quantity = "1",
title = "titulo 001"
},
new ImportXsd.shiporderItem {
note = "nota 002",
price = 200,
quantity = "2",
title = "titulo 002"
}
};
var xml = string.Empty;
var serialize = new XmlSerializer(typeof(ImportXsd.shiporder));
using (var strignWriter = new StringWriter())
{
using (var xmlWriter = XmlWriter.Create(strignWriter, new XmlWriterSettings { Indent = true }))
{
serialize.Serialize(xmlWriter, order);
xml = strignWriter.ToString();
}
}
using (var strignReader = new StringReader(xml))
{
using (var xmlReader = XmlReader.Create(strignReader))
{
order = serialize.Deserialize(xmlReader) as ImportXsd.shiporder;
}
}
in the above example, the generated XML was something like.:
<?xml version="1.0" encoding="utf-16"?>
<shiporder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" orderid="ordemServico">
<orderperson>destinatario</orderperson>
<shipto>
<name>nome</name>
<address>endereço</address>
<city>cidade</city>
<country>pais</country>
</shipto>
<item>
<title>titulo 001</title>
<note>nota 001</note>
<quantity>1</quantity>
<price>100</price>
</item>
<item>
<title>titulo 002</title>
<note>nota 002</note>
<quantity>2</quantity>
<price>200</price>
</item>
</shiporder>
It is difficult to get a diagnosis only with this information, maybe your XML has special characters or quotes that are breaking the string. Debugging, you checked the generated xml for the request?
– Leandro Angelo
It seems that the service requires SOAP Protocol for the communication between messages exchanges. How is the xml you are sending ? Enter the final xml for more information...
– Henrique