"Unable to strip payload from SOAP envelope" using ParkSquare.SoapClient - c#

I try to challenge generated svcUtil SOAP Client with alternative approach.
Although the svcUtil approach works well but as it is using a persistent WCF channel to the Saop Server we would like to try to avoid this always connected behavior. In the other hand svcUtil does a great job by generating DTO from the wsdl so we would like to use it only for the DTO.
SparkQuare provide a SoapClient nuget which use a standard HttpClient and then fits our goal. However I get trouble to set it up properly.
Currently I get this error :
System.AggregateException : One or more errors occurred. (Unable to strip payload from SOAP envelope)
---- ParkSquare.SoapClient.SoapHttpClientException : Unable to strip payload from SOAP envelope
My guess is I did not properly set up defaultNamespace and action but I didn't find relevant documentation yet. Anyone got hints about it?
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using ParkSquare.SoapClient;
using System.Net.Http.Headers;
using System.Text;
using Soap_sern_mvt_ServiceReference; //DTO generated by SvcUtil
namespace ErpApi.EndPoint.ParkSquareSoapClient
{
public class SerialNumberMouvementParkSquareSoapClient : ISerialNumberMouvement
{
private ISoapClient _soapClient;
private HttpClient _httpClient;
public SerialNumberMouvementParkSquareSoapClient()
{
string cred = "some:credentials";
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(Encoding.ASCII.GetBytes(cred)));
_soapClient = new ParkSquare.SoapClient.SoapClient(
_httpClient,
new RawBodySerializer(),
new SoapHttpRequestBuilder(),
new PayloadStripper(),
new BodyDeserializer());
}
public async Task<IEnumerable<string>> GetAsync(string serialNumber)
{
ZsdSernMvtRequest requestDto = new ZsdSernMvtRequest();
ZsdSernMvt data = new ZsdSernMvt
{
EtSernrMvt = new List<ZsdSSernrSalesMvt>().ToArray(),
IndividualSerialNumber = serialNumber
};
requestDto.ZsdSernMvt = data;
//Exception will fire here :
var responseDto = await _soapClient.PostAsync<ZsdSernMvtRequest, ZsdSernMvtResponse1>(
endpoint: new Uri("http://theSoapServer/sap/bc/srt/rfc/sap/zws_sern_mvt/010/zome_sern_mvt/zome_sern_mvt?sap-client=010"),
request: requestDto,
defaultNamespace: "urn:sap-com:document:sap:soap:functions:mc-style",
action: "urn:sap-com:document:sap:soap:functions:mc-style:ZWS_SERN_MVT:ZsdSernMvtRequest",
SoapVersion.Soap12);
return new List<string>() { responseDto.ToString() };
}
}
}
for reference below is the code generated by svcutil which contains DTO used above.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Soap_sern_mvt_ServiceReference
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.ServiceModel.ServiceContractAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", ConfigurationName="Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT")]
public interface ZWS_SERN_MVT
{
[System.ServiceModel.OperationContractAttribute(Action="urn:sap-com:document:sap:soap:functions:mc-style:ZWS_SERN_MVT:ZsdSernMvtRequest", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse1> ZsdSernMvtAsync(Soap_sern_mvt_ServiceReference.ZsdSernMvtRequest request);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
public partial class ZsdSernMvt
{
private ZsdSSernrSalesMvt[] etSernrMvtField;
private string individualSerialNumberField;
private ZsdSSernr[] multipleSerialNumbersField;
private string productIsAWatchField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public ZsdSSernrSalesMvt[] EtSernrMvt
{
get
{
return this.etSernrMvtField;
}
set
{
this.etSernrMvtField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string IndividualSerialNumber
{
get
{
return this.individualSerialNumberField;
}
set
{
this.individualSerialNumberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public ZsdSSernr[] MultipleSerialNumbers
{
get
{
return this.multipleSerialNumbersField;
}
set
{
this.multipleSerialNumbersField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string ProductIsAWatch
{
get
{
return this.productIsAWatchField;
}
set
{
this.productIsAWatchField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
public partial class ZsdSSernrSalesMvt
{
private string brand_codeField;
private string intercompagy_codeField;
private string serial_numberField;
private string product_SAP_numberField;
private string receipt_dateField;
private string sales_dateField;
private string customer_numberField;
private string nameField;
private string additional_textField;
private string movement_codeField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string Brand_code
{
get
{
return this.brand_codeField;
}
set
{
this.brand_codeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string Intercompagy_code
{
get
{
return this.intercompagy_codeField;
}
set
{
this.intercompagy_codeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string Serial_number
{
get
{
return this.serial_numberField;
}
set
{
this.serial_numberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string Product_SAP_number
{
get
{
return this.product_SAP_numberField;
}
set
{
this.product_SAP_numberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
public string Receipt_date
{
get
{
return this.receipt_dateField;
}
set
{
this.receipt_dateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
public string Sales_date
{
get
{
return this.sales_dateField;
}
set
{
this.sales_dateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
public string Customer_number
{
get
{
return this.customer_numberField;
}
set
{
this.customer_numberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
public string Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
public string Additional_text
{
get
{
return this.additional_textField;
}
set
{
this.additional_textField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=9)]
public string Movement_code
{
get
{
return this.movement_codeField;
}
set
{
this.movement_codeField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
public partial class ZsdSSernr
{
private string serial_numberField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string Serial_number
{
get
{
return this.serial_numberField;
}
set
{
this.serial_numberField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
public partial class ZsdSernMvtResponse
{
private ZsdSSernrSalesMvt[] etSernrMvtField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public ZsdSSernrSalesMvt[] EtSernrMvt
{
get
{
return this.etSernrMvtField;
}
set
{
this.etSernrMvtField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class ZsdSernMvtRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
public Soap_sern_mvt_ServiceReference.ZsdSernMvt ZsdSernMvt;
public ZsdSernMvtRequest()
{
}
public ZsdSernMvtRequest(Soap_sern_mvt_ServiceReference.ZsdSernMvt ZsdSernMvt)
{
this.ZsdSernMvt = ZsdSernMvt;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class ZsdSernMvtResponse1
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
public Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse ZsdSernMvtResponse;
public ZsdSernMvtResponse1()
{
}
public ZsdSernMvtResponse1(Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse ZsdSernMvtResponse)
{
this.ZsdSernMvtResponse = ZsdSernMvtResponse;
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
public interface ZWS_SERN_MVTChannel : Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
public partial class ZWS_SERN_MVTClient : System.ServiceModel.ClientBase<Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT>, Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT
{
public ZWS_SERN_MVTClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public System.Threading.Tasks.Task<Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse1> ZsdSernMvtAsync(Soap_sern_mvt_ServiceReference.ZsdSernMvtRequest request)
{
return base.Channel.ZsdSernMvtAsync(request);
}
public virtual System.Threading.Tasks.Task OpenAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}
public virtual System.Threading.Tasks.Task CloseAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}
}
}

Do you have the full stack trace that results in that exception?
Also, a full (valid) SOAP request that is sent across the wire by the generated client? You could get this by running Fiddler (or similar) to capture the request.

Related

Incorrect deserialization of SOAP message in .NET app

I am working on converting an existing application from .NET Framework to .NET 6. Deserialization of SOAP message no longer works as expected.
I have the following response message:
<?xml version="1.0" encoding="utf-16"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<S:Body>
<ns2:findAgreementResponse
xmlns:ns2="example.webservices.licensing.secure"
xmlns:ns3="example.webservices.exceptions">
<return>
<description>Standard</description>
<idLicenseAgreement>1234</idLicenseAgreement>
</return>
</ns2:findAgreementResponse>
</S:Body>
</S:Envelope>
With the .NET Framework, the code generated when I added a service reference included this:
[System.Xml.Serialization.XmlIncludeAttribute(typeof(agreement))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3221.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/licensing/")]
public partial class messageBase {
private System.Xml.XmlElement[] anyField;
private string messageIdField;
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Any {
get { return this.anyField; }
set { this.anyField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string messageId {
get { return this.messageIdField; }
set { this.messageIdField = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3221.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/licensing/")]
public partial class agreement : messageBase {
private string descriptionField;
private long idLicenseAgreementField;
private bool idLicenseAgreementFieldSpecified;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string description {
get { return this.descriptionField; }
set { this.descriptionField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public long idLicenseAgreement {
get { return this.idLicenseAgreementField; }
set { this.idLicenseAgreementField = value; }
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool idLicenseAgreementSpecified {
get { return this.idLicenseAgreementFieldSpecified; }
set { this.idLicenseAgreementFieldSpecified = value; }
}
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="example.webservices.licensing.secure", ResponseNamespace="example.webservices.licensing.secure", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public agreement findAgreement([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string arg0) {
object[] results = this.Invoke("findAgreement", new object[] {
arg0});
return ((agreement)(results[0]));
}
This worked well, the response was properly deserialized (when calling the findAgreement method). When something was not expected (there are many methods and responses), it was added to the Any array from messageBase.
After migrating to .NET 6, adding the service resulted in the following code:
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(agreement))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/licensing/")]
public partial class messageBase
{
private System.Xml.XmlElement[] anyField;
private string messageIdField;
[System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
public System.Xml.XmlElement[] Any
{
get { return this.anyField; }
set { this.anyField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string messageId
{
get { return this.messageIdField; }
set { this.messageIdField = value; }
}
}
[System.SerializableAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/licensing/")]
public partial class agreement : messageBase
{
private string descriptionField;
private long idLicenseAgreementField;
private bool idLicenseAgreementFieldSpecified;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string description
{
get { return this.descriptionField; }
set { this.descriptionField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public long idLicenseAgreement
{
get { return this.idLicenseAgreementField; }
set { this.idLicenseAgreementField = value; }
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool idLicenseAgreementSpecified
{
get { return this.idLicenseAgreementFieldSpecified; }
set { this.idLicenseAgreementFieldSpecified = value; }
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="findAgreementResponse", WrapperNamespace="example.webservices.licensing.secure", IsWrapped=true)]
public partial class findAgreementResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="example.webservices.licensing.secure", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public agreement #return;
public findAgreementResponse()
{
}
public findAgreementResponse(agreement #return)
{
this.#return = #return;
}
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
findAgreementResponse findAgreement(findAgreementRequest request)
{
return base.Channel.findAgreement(request);
}
What happens now is that the description and idLicenseAgreement properties are not filled in. Instead, the Any array from the base class contains both these XML elements:
<description>Standard</description>
<idLicenseAgreement>1234</idLicenseAgreement>
If I remove the messageBase base class, parsing occurs correctly, and the agreement object is properly filled in with the data from the SOAP response.
I expect this to be a namespace issue but I was unable to figure it out.
I figured out the problem was the explicit ordering of elements. In the code generated by Svcutil in .NET 6, all the XML elements are attributed like this:
[System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
Once I removed the Order property from all of them, deserialization worked as expected.

Deserialize a XML to C# class from a wsdl

I am using a Web Service (wsdl), and I need to add a XML(that I receive) to my request, I added the web reference to Visual Studio and it generated a few classes.
I need to add a rDE instance to my request so I tried deserializing the XML using the generated classes, it doesn't throw an Exception but all the properties are null, I have been able to send the same XML through postman so the XML is ok, I don't know if I have the correct approach here since is my first time doing this.
These are the generated classes
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.4084.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="*")]
public partial class rDE {
private string dVerForField;
private DE deField;
private gCamFuFD gCamFuFDField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string dVerFor {
get {
return this.dVerForField;
}
set {
this.dVerForField = value;
}
}
/// <remarks/>
public DE DE {
get {
return this.deField;
}
set {
this.deField = value;
}
}
/// <remarks/>
public gCamFuFD gCamFuFD {
get {
return this.gCamFuFDField;
}
set {
this.gCamFuFDField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.4084.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="*")]
public partial class DE {
private string dDVIdField;
private System.DateTime dFecFirmaField;
private bool dFecFirmaFieldSpecified;
private string dSisFactField;
private gOpeDE gOpeDEField;
private gTimb gTimbField;
private gDatGralOpe gDatGralOpeField;
private gDtipDE gDtipDEField;
private gTotSub gTotSubField;
private gCamGen gCamGenField;
private gCamDEAsoc[] gCamDEAsocField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string dDVId {
get {
return this.dDVIdField;
}
set {
this.dDVIdField = value;
}
}
/// <remarks/>
public System.DateTime dFecFirma {
get {
return this.dFecFirmaField;
}
set {
this.dFecFirmaField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool dFecFirmaSpecified {
get {
return this.dFecFirmaFieldSpecified;
}
set {
this.dFecFirmaFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string dSisFact {
get {
return this.dSisFactField;
}
set {
this.dSisFactField = value;
}
}
/// <remarks/>
public gOpeDE gOpeDE {
get {
return this.gOpeDEField;
}
set {
this.gOpeDEField = value;
}
}
/// <remarks/>
public gTimb gTimb {
get {
return this.gTimbField;
}
set {
this.gTimbField = value;
}
}
/// <remarks/>
public gDatGralOpe gDatGralOpe {
get {
return this.gDatGralOpeField;
}
set {
this.gDatGralOpeField = value;
}
}
/// <remarks/>
public gDtipDE gDtipDE {
get {
return this.gDtipDEField;
}
set {
this.gDtipDEField = value;
}
}
/// <remarks/>
public gTotSub gTotSub {
get {
return this.gTotSubField;
}
set {
this.gTotSubField = value;
}
}
/// <remarks/>
public gCamGen gCamGen {
get {
return this.gCamGenField;
}
set {
this.gCamGenField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("gCamDEAsoc")]
public gCamDEAsoc[] gCamDEAsoc {
get {
return this.gCamDEAsocField;
}
set {
this.gCamDEAsocField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.4084.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="*")]
public partial class gOpeDE {
private string iTipEmiField;
private string dDesTipEmiField;
private string dCodSegField;
private string dInfoEmiField;
private string dInfoFiscField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string iTipEmi {
get {
return this.iTipEmiField;
}
set {
this.iTipEmiField = value;
}
}
/// <remarks/>
public string dDesTipEmi {
get {
return this.dDesTipEmiField;
}
set {
this.dDesTipEmiField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string dCodSeg {
get {
return this.dCodSegField;
}
set {
this.dCodSegField = value;
}
}
/// <remarks/>
public string dInfoEmi {
get {
return this.dInfoEmiField;
}
set {
this.dInfoEmiField = value;
}
}
/// <remarks/>
public string dInfoFisc {
get {
return this.dInfoFiscField;
}
set {
this.dInfoFiscField = value;
}
}
}
and this is my XML(Its Elements may vary, it can have more or less elements but this is the XML I have been using to test)
<rDE>
<DE>
<gOpeDE>
<iTipEmi>1</iTipEmi>
</gOpeDE>
<gTimb>
<iTiDE>1</iTiDE>
<dNumTim>14601619</dNumTim>
<dEst>9</dEst>
<dPunExp>9</dPunExp>
<dNumDoc>22712</dNumDoc>
</gTimb>
<gDatGralOpe>
<dFeEmiDE>12/04/2022</dFeEmiDE>
<gOpeCom>
<iTipTra>1</iTipTra>
<iTImp>1</iTImp>
<cMoneOpe>PYG</cMoneOpe>
</gOpeCom>
<gEmis>
<dRucEm>800486946</dRucEm>
<dDVEmi>4</dDVEmi>
</gEmis>
<gDatRec>
<iNatRec>1</iNatRec>
<iTiOpe>1</iTiOpe>
<dRucRec>5307630</dRucRec>
<dDVRec>3</dDVRec>
<iTiContRec>1</iTiContRec>
<dNomRec>BARRETO MENDEZ EDER MATIAS</dNomRec>
<dDirRec>A</dDirRec>
<dNumCasRec>0</dNumCasRec>
<cPaisRec>PRY</cPaisRec>
<dDesPaisRe>Paraguay</dDesPaisRe>
</gDatRec>
</gDatGralOpe>
<gDtipDE>
<gCamFE>
<iIndPres>1</iIndPres>
</gCamFE>
<gCamItem>
<dCodInt>614143297809</dCodInt>
<dDesProSer>R CAPELETIS - POLLO 500GR PAQ </dDesProSer>
<dCantProSer>3.00</dCantProSer>
<gValorItem>
<dPUniProSer>12500</dPUniProSer>
<dTotBruOpeItem>37500</dTotBruOpeItem>
<gValorRestaItem>
<dDescItem>0</dDescItem>
<dTotOpeItem>37500</dTotOpeItem>
</gValorRestaItem>
</gValorItem>
<gCamIVA>
<iAfecIVA>1</iAfecIVA>
<dTasaIVA>10</dTasaIVA>
</gCamIVA>
</gCamItem>
<gCamCond>
<iCondOpe>1</iCondOpe>
</gCamCond>
</gDtipDE>
<gTotSub>
<dSubExe>0</dSubExe>
<dSub5>0</dSub5>
<dSub10>37500</dSub10>
<dTotOpe>37500</dTotOpe>
<dRedon>0</dRedon>
</gTotSub>
</DE>
</rDE>
This is where I deserialize
public rDE deserializeXML(string xml)
{
rDE obj = new rDE();
XmlSerializer serializer = new XmlSerializer(typeof(rDE));
byte[] byteArray = Encoding.UTF8.GetBytes(xml);
MemoryStream stream = new MemoryStream(byteArray);
StreamReader reader = new StreamReader(stream);
obj = (rDE)serializer.Deserialize(reader);
return obj;
}

I tried to add SAP webservice link to my service reference and alot of error appear

So I already added the service reference and straight away I got this errors.
I haven't even started programming yet.
https://ibb.co/kBhp2pZ
I haven't even started coding yet and try to build the solution but It's giving me error in the script called Reference.cs.
I tried resolving the error but to no avail
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test_web_SAP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
I've also included the auto generated code from my visual studio
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace test_web_SAP.SAP_WEB_SERVICE {
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", ConfigurationName="SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK")]
public interface ZWM_MY_I_BARC_STOCK {
// CODEGEN: Generating message contract since the operation ZWM_MY_I_BARC_STOCK is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="urn:sap-com:document:sap:rfc:functions:ZWM_MY_I_BARC_STOCK:ZWM_MY_I_BARC_STOCKReq" +
"uest", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1 ZWM_MY_I_BARC_STOCK(test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest request);
[System.ServiceModel.OperationContractAttribute(Action="urn:sap-com:document:sap:rfc:functions:ZWM_MY_I_BARC_STOCK:ZWM_MY_I_BARC_STOCKReq" +
"uest", ReplyAction="*")]
System.Threading.Tasks.Task<test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1> ZWM_MY_I_BARC_STOCKAsync(test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest request);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:rfc:functions")]
public partial class ZWM_MY_I_BARC_STOCK : object, System.ComponentModel.INotifyPropertyChanged {
private string bATCHField;
private string mATERIALField;
private string pLANTField;
private string sPEC_STOCKField;
private string sTOCK_CATField;
private string sTORAGE_BINField;
private string sTORAGE_LOCField;
private string sTORAGE_TYPEField;
private string wAREHOUSE_NOField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string BATCH {
get {
return this.bATCHField;
}
set {
this.bATCHField = value;
this.RaisePropertyChanged("BATCH");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string MATERIAL {
get {
return this.mATERIALField;
}
set {
this.mATERIALField = value;
this.RaisePropertyChanged("MATERIAL");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string PLANT {
get {
return this.pLANTField;
}
set {
this.pLANTField = value;
this.RaisePropertyChanged("PLANT");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string SPEC_STOCK {
get {
return this.sPEC_STOCKField;
}
set {
this.sPEC_STOCKField = value;
this.RaisePropertyChanged("SPEC_STOCK");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
public string STOCK_CAT {
get {
return this.sTOCK_CATField;
}
set {
this.sTOCK_CATField = value;
this.RaisePropertyChanged("STOCK_CAT");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
public string STORAGE_BIN {
get {
return this.sTORAGE_BINField;
}
set {
this.sTORAGE_BINField = value;
this.RaisePropertyChanged("STORAGE_BIN");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
public string STORAGE_LOC {
get {
return this.sTORAGE_LOCField;
}
set {
this.sTORAGE_LOCField = value;
this.RaisePropertyChanged("STORAGE_LOC");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
public string STORAGE_TYPE {
get {
return this.sTORAGE_TYPEField;
}
set {
this.sTORAGE_TYPEField = value;
this.RaisePropertyChanged("STORAGE_TYPE");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
public string WAREHOUSE_NO {
get {
return this.wAREHOUSE_NOField;
}
set {
this.wAREHOUSE_NOField = value;
this.RaisePropertyChanged("WAREHOUSE_NO");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:rfc:functions")]
public partial class ZWM_MY_I_FM_BARCODE_MS : object, System.ComponentModel.INotifyPropertyChanged {
private string tYPEField;
private string mESSAGEField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string TYPE {
get {
return this.tYPEField;
}
set {
this.tYPEField = value;
this.RaisePropertyChanged("TYPE");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string MESSAGE {
get {
return this.mESSAGEField;
}
set {
this.mESSAGEField = value;
this.RaisePropertyChanged("MESSAGE");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:rfc:functions")]
public partial class ZWM_MY_I_BARC_STOCK_S : object, System.ComponentModel.INotifyPropertyChanged {
private string mATERIALField;
private string sTGE_LOCField;
private string sTGE_TYPEField;
private string sTGE_BINField;
private decimal qUANTITYField;
private string uOMField;
private string bATCHField;
private string sTOCK_CATField;
private string sPEC_STOCKField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string MATERIAL {
get {
return this.mATERIALField;
}
set {
this.mATERIALField = value;
this.RaisePropertyChanged("MATERIAL");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string STGE_LOC {
get {
return this.sTGE_LOCField;
}
set {
this.sTGE_LOCField = value;
this.RaisePropertyChanged("STGE_LOC");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string STGE_TYPE {
get {
return this.sTGE_TYPEField;
}
set {
this.sTGE_TYPEField = value;
this.RaisePropertyChanged("STGE_TYPE");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string STGE_BIN {
get {
return this.sTGE_BINField;
}
set {
this.sTGE_BINField = value;
this.RaisePropertyChanged("STGE_BIN");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
public decimal QUANTITY {
get {
return this.qUANTITYField;
}
set {
this.qUANTITYField = value;
this.RaisePropertyChanged("QUANTITY");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
public string UOM {
get {
return this.uOMField;
}
set {
this.uOMField = value;
this.RaisePropertyChanged("UOM");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
public string BATCH {
get {
return this.bATCHField;
}
set {
this.bATCHField = value;
this.RaisePropertyChanged("BATCH");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
public string STOCK_CAT {
get {
return this.sTOCK_CATField;
}
set {
this.sTOCK_CATField = value;
this.RaisePropertyChanged("STOCK_CAT");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
public string SPEC_STOCK {
get {
return this.sPEC_STOCKField;
}
set {
this.sPEC_STOCKField = value;
this.RaisePropertyChanged("SPEC_STOCK");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:rfc:functions")]
public partial class ZWM_MY_I_BARC_STOCKResponse : object, System.ComponentModel.INotifyPropertyChanged {
private ZWM_MY_I_BARC_STOCK_S[] iTEMField;
private ZWM_MY_I_FM_BARCODE_MS mSGField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public ZWM_MY_I_BARC_STOCK_S[] ITEM {
get {
return this.iTEMField;
}
set {
this.iTEMField = value;
this.RaisePropertyChanged("ITEM");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public ZWM_MY_I_FM_BARCODE_MS MSG {
get {
return this.mSGField;
}
set {
this.mSGField = value;
this.RaisePropertyChanged("MSG");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class ZWM_MY_I_BARC_STOCKRequest {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", Order=0)]
public test_web_SAP.SAP_WEB_SERVICE.test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK ZWM_MY_I_BARC_STOCK;
public ZWM_MY_I_BARC_STOCKRequest() {
}
public ZWM_MY_I_BARC_STOCKRequest(test_web_SAP.SAP_WEB_SERVICE.test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK ZWM_MY_I_BARC_STOCK) {
this.ZWM_MY_I_BARC_STOCK = ZWM_MY_I_BARC_STOCK;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class ZWM_MY_I_BARC_STOCKResponse1 {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", Order=0)]
public test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse ZWM_MY_I_BARC_STOCKResponse;
public ZWM_MY_I_BARC_STOCKResponse1() {
}
public ZWM_MY_I_BARC_STOCKResponse1(test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse ZWM_MY_I_BARC_STOCKResponse) {
this.ZWM_MY_I_BARC_STOCKResponse = ZWM_MY_I_BARC_STOCKResponse;
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ZWM_MY_I_BARC_STOCKChannel : test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class ZWM_MY_I_BARC_STOCKClient : System.ServiceModel.ClientBase<test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK>, test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK {
public ZWM_MY_I_BARC_STOCKClient() {
}
public ZWM_MY_I_BARC_STOCKClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public ZWM_MY_I_BARC_STOCKClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public ZWM_MY_I_BARC_STOCKClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public ZWM_MY_I_BARC_STOCKClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1 test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK.ZWM_MY_I_BARC_STOCK(test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest request) {
return base.Channel.ZWM_MY_I_BARC_STOCK(request);
}
public test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse ZWM_MY_I_BARC_STOCK(test_web_SAP.SAP_WEB_SERVICE.test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK ZWM_MY_I_BARC_STOCK1) {
test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest inValue = new test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest();
inValue.ZWM_MY_I_BARC_STOCK = ZWM_MY_I_BARC_STOCK1;
test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1 retVal = ((test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK)(this)).ZWM_MY_I_BARC_STOCK(inValue);
return retVal.ZWM_MY_I_BARC_STOCKResponse;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.Threading.Tasks.Task<test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1> test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK.ZWM_MY_I_BARC_STOCKAsync(test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest request) {
return base.Channel.ZWM_MY_I_BARC_STOCKAsync(request);
}
public System.Threading.Tasks.Task<test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKResponse1> ZWM_MY_I_BARC_STOCKAsync(test_web_SAP.SAP_WEB_SERVICE.test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK ZWM_MY_I_BARC_STOCK) {
test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest inValue = new test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCKRequest();
inValue.ZWM_MY_I_BARC_STOCK = ZWM_MY_I_BARC_STOCK;
return ((test_web_SAP.SAP_WEB_SERVICE.ZWM_MY_I_BARC_STOCK)(this)).ZWM_MY_I_BARC_STOCKAsync(inValue);
}
}
}

My code is throwing an error and i am unable to fix, What way could i solve this or how would I be able to change it to work?

I am getting this error when I run my code
System.InvalidOperationException
HResult=0x80131509
Message=HamiltonXML.Program is inaccessible due to its protection
level. Only public types can be processed.
Source=System.Xmlenter code here
StackTrace:
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type,
MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at HamiltonXML.Program.Main(String[] args) in C:\Users\Aube\source\repos\HamiltonProject\HamiltonProject\Program.cs:line 18
I've changed all classes to public and rechecked all of the code yet the problem still occurs. Here is the code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace HamiltonXML
{
class Program
{
static void Main(string[] args)
{
EnvironmentNodeConfigurationParameters encp = null;
string path = "C:/Users/Aube/Desktop/FreezerEnvironmentNodeParameters_Freezer1.xml";
XmlSerializer serializer = new XmlSerializer(typeof(EnvironmentNodeConfigurationParameters));
StreamReader reader = new StreamReader(path);
encp = (EnvironmentNodeConfigurationParameters)serializer.Deserialize(reader);
reader.Close();
}
// NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class EnvironmentNodeConfigurationParameters
{
private EnvironmentNodeConfigurationParametersComplexNodeConfigurations[] complexDeviceParameterListField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("ComplexNodeConfigurations", IsNullable = false)]
public EnvironmentNodeConfigurationParametersComplexNodeConfigurations[] ComplexDeviceParameterList
{
get
{
return this.complexDeviceParameterListField;
}
set
{
this.complexDeviceParameterListField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class EnvironmentNodeConfigurationParametersComplexNodeConfigurations
{
private EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurations[] complexNodeParameterListField;
private string subDeviceIDField;
private string subDeviceNameField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("NodeConfigurations", IsNullable = false)]
public EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurations[] ComplexNodeParameterList
{
get
{
return this.complexNodeParameterListField;
}
set
{
this.complexNodeParameterListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string SubDeviceID
{
get
{
return this.subDeviceIDField;
}
set
{
this.subDeviceIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string SubDeviceName
{
get
{
return this.subDeviceNameField;
}
set
{
this.subDeviceNameField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurations
{
private EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParams environmentLinkParamsField;
private byte nodeIDField;
private string nodeNameField;
private string dependNodeNameField;
private string registerTypeField;
private byte startRegField;
private byte numRegsField;
private string nodeTypeField;
private string valueTypeField;
private string environmentLinkTypeField;
private string guidField;
private bool enabledField;
private string unitsField;
private bool monitoredField;
private byte reportItemField;
/// <remarks/>
public EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParams EnvironmentLinkParams
{
get
{
return this.environmentLinkParamsField;
}
set
{
this.environmentLinkParamsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public byte NodeID
{
get
{
return this.nodeIDField;
}
set
{
this.nodeIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string NodeName
{
get
{
return this.nodeNameField;
}
set
{
this.nodeNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DependNodeName
{
get
{
return this.dependNodeNameField;
}
set
{
this.dependNodeNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string RegisterType
{
get
{
return this.registerTypeField;
}
set
{
this.registerTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public byte StartReg
{
get
{
return this.startRegField;
}
set
{
this.startRegField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public byte NumRegs
{
get
{
return this.numRegsField;
}
set
{
this.numRegsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string NodeType
{
get
{
return this.nodeTypeField;
}
set
{
this.nodeTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ValueType
{
get
{
return this.valueTypeField;
}
set
{
this.valueTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string EnvironmentLinkType
{
get
{
return this.environmentLinkTypeField;
}
set
{
this.environmentLinkTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Guid
{
get
{
return this.guidField;
}
set
{
this.guidField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public bool Enabled
{
get
{
return this.enabledField;
}
set
{
this.enabledField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Units
{
get
{
return this.unitsField;
}
set
{
this.unitsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public bool Monitored
{
get
{
return this.monitoredField;
}
set
{
this.monitoredField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public byte ReportItem
{
get
{
return this.reportItemField;
}
set
{
this.reportItemField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParams
{
private EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParamsKeyValuePair keyValuePairField;
/// <remarks/>
public EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParamsKeyValuePair KeyValuePair
{
get
{
return this.keyValuePairField;
}
set
{
this.keyValuePairField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class EnvironmentNodeConfigurationParametersComplexNodeConfigurationsNodeConfigurationsEnvironmentLinkParamsKeyValuePair
{
private string keyField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Key
{
get
{
return this.keyField;
}
set
{
this.keyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
}
}
The code is supposed to deserialize an XML file.
Have you tried changing your Program class to public?
namespace HamiltonXML
{
public class Program
{

How to Deserializes this XML document to generated C# class

I have tried to read XML document and i have found a method of generating XSD file into a C# class.
XML Document :
<?xml version="1.0" standalone="yes"?>
<sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd">
<publshInformation>
<Publish_Date>12/15/2011</Publish_Date>
<Record_Count>5052</Record_Count>
</publshInformation>
<sdnEntry>
<uid>11691</uid>
<lastName>SERVICIOS DE CONTROL INTEGRAL DE OBRAS S.L. SIP SUCURSAL CARTAGENA</lastName>
<sdnType>Entity</sdnType>
<programList>
<program>SDNT</program>
</programList>
<idList>
<id>
<uid>6028</uid>
<idType>NIT #</idType>
<idNumber>900106267-0</idNumber>
<idCountry>Colombia</idCountry>
</id>
</idList>
<addressList>
<address>
<uid>17543</uid>
<address1>Carrera 3 No. 8-38</address1>
<city>Cartagena</city>
<country>Colombia</country>
</address>
<address>
<uid>17544</uid>
<address1>Carrera 4 No. 8-41</address1>
<city>Cartagena</city>
<country>Colombia</country>
</address>
</addressList>
</sdnEntry>
<sdnEntry>
<uid>11692</uid>
<lastName>INVERSIONES EL PROGRESO S.A.</lastName>
<sdnType>Entity</sdnType>
<programList>
<program>SDNT</program>
</programList>
<idList>
<id>
<uid>6027</uid>
<idType>NIT #</idType>
<idNumber>806006517-7</idNumber>
<idCountry>Colombia</idCountry>
</id>
</idList>
<akaList>
<aka>
<uid>12373</uid>
<type>a.k.a.</type>
<category>weak</category>
<lastName>I.P. S.A.</lastName>
</aka>
</akaList>
<addressList>
<address>
<uid>17540</uid>
<address1>Carrera 3 No. 8-38 Ofc. 1</address1>
<city>Cartagena</city>
<country>Colombia</country>
</address>
<address>
<uid>17541</uid>
<address1>Carrera 4 No. 8-41</address1>
<city>Cartagena</city>
<country>Colombia</country>
</address>
<address>
<uid>17542</uid>
<address1>Olaya Herrera Carrera 68 No. 32B-45</address1>
<city>Cartagena</city>
<country>Colombia</country>
</address>
</addressList>
</sdnEntry>
Generated C# Class by XSD tool
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.5448
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://tempuri.org/sdnList.xsd", IsNullable = false)]
public partial class sdnList
{
private sdnListPublshInformation publshInformationField;
private sdnListSdnEntry[] sdnEntryField;
/// <remarks/>
public sdnListPublshInformation publshInformation
{
get
{
return this.publshInformationField;
}
set
{
this.publshInformationField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("sdnEntry")]
public sdnListSdnEntry[] sdnEntry
{
get
{
return this.sdnEntryField;
}
set
{
this.sdnEntryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListPublshInformation
{
private string publish_DateField;
private int record_CountField;
private bool record_CountFieldSpecified;
/// <remarks/>
public string Publish_Date
{
get
{
return this.publish_DateField;
}
set
{
this.publish_DateField = value;
}
}
/// <remarks/>
public int Record_Count
{
get
{
return this.record_CountField;
}
set
{
this.record_CountField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool Record_CountSpecified
{
get
{
return this.record_CountFieldSpecified;
}
set
{
this.record_CountFieldSpecified = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntry
{
private int uidField;
private string firstNameField;
private string lastNameField;
private string titleField;
private string sdnTypeField;
private string remarksField;
private string[] programListField;
private sdnListSdnEntryID[] idListField;
private sdnListSdnEntryAka[] akaListField;
private sdnListSdnEntryAddress[] addressListField;
private sdnListSdnEntryNationality[] nationalityListField;
private sdnListSdnEntryCitizenship[] citizenshipListField;
private sdnListSdnEntryDateOfBirthItem[] dateOfBirthListField;
private sdnListSdnEntryPlaceOfBirthItem[] placeOfBirthListField;
private sdnListSdnEntryVesselInfo vesselInfoField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string firstName
{
get
{
return this.firstNameField;
}
set
{
this.firstNameField = value;
}
}
/// <remarks/>
public string lastName
{
get
{
return this.lastNameField;
}
set
{
this.lastNameField = value;
}
}
/// <remarks/>
public string title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}
/// <remarks/>
public string sdnType
{
get
{
return this.sdnTypeField;
}
set
{
this.sdnTypeField = value;
}
}
/// <remarks/>
public string remarks
{
get
{
return this.remarksField;
}
set
{
this.remarksField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("program", IsNullable = false)]
public string[] programList
{
get
{
return this.programListField;
}
set
{
this.programListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("id", IsNullable = false)]
public sdnListSdnEntryID[] idList
{
get
{
return this.idListField;
}
set
{
this.idListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("aka", IsNullable = false)]
public sdnListSdnEntryAka[] akaList
{
get
{
return this.akaListField;
}
set
{
this.akaListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("address", IsNullable = false)]
public sdnListSdnEntryAddress[] addressList
{
get
{
return this.addressListField;
}
set
{
this.addressListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("nationality", IsNullable = false)]
public sdnListSdnEntryNationality[] nationalityList
{
get
{
return this.nationalityListField;
}
set
{
this.nationalityListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("citizenship", IsNullable = false)]
public sdnListSdnEntryCitizenship[] citizenshipList
{
get
{
return this.citizenshipListField;
}
set
{
this.citizenshipListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("dateOfBirthItem", IsNullable = false)]
public sdnListSdnEntryDateOfBirthItem[] dateOfBirthList
{
get
{
return this.dateOfBirthListField;
}
set
{
this.dateOfBirthListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("placeOfBirthItem", IsNullable = false)]
public sdnListSdnEntryPlaceOfBirthItem[] placeOfBirthList
{
get
{
return this.placeOfBirthListField;
}
set
{
this.placeOfBirthListField = value;
}
}
/// <remarks/>
public sdnListSdnEntryVesselInfo vesselInfo
{
get
{
return this.vesselInfoField;
}
set
{
this.vesselInfoField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryID
{
private int uidField;
private string idTypeField;
private string idNidCountryumberField;
private string idCountryField;
private string issueDateField;
private string expirationDateField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string idType
{
get
{
return this.idTypeField;
}
set
{
this.idTypeField = value;
}
}
/// <remarks/>
public string idNidCountryumber
{
get
{
return this.idNidCountryumberField;
}
set
{
this.idNidCountryumberField = value;
}
}
/// <remarks/>
public string idCountry
{
get
{
return this.idCountryField;
}
set
{
this.idCountryField = value;
}
}
/// <remarks/>
public string issueDate
{
get
{
return this.issueDateField;
}
set
{
this.issueDateField = value;
}
}
/// <remarks/>
public string expirationDate
{
get
{
return this.expirationDateField;
}
set
{
this.expirationDateField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryAka
{
private int uidField;
private string typeField;
private string categoryField;
private string lastNameField;
private string firstNameField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}
/// <remarks/>
public string category
{
get
{
return this.categoryField;
}
set
{
this.categoryField = value;
}
}
/// <remarks/>
public string lastName
{
get
{
return this.lastNameField;
}
set
{
this.lastNameField = value;
}
}
/// <remarks/>
public string firstName
{
get
{
return this.firstNameField;
}
set
{
this.firstNameField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryAddress
{
private int uidField;
private string address1Field;
private string address2Field;
private string address3Field;
private string cityField;
private string stateOrProvinceField;
private string postalCodeField;
private string countryField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string address1
{
get
{
return this.address1Field;
}
set
{
this.address1Field = value;
}
}
/// <remarks/>
public string address2
{
get
{
return this.address2Field;
}
set
{
this.address2Field = value;
}
}
/// <remarks/>
public string address3
{
get
{
return this.address3Field;
}
set
{
this.address3Field = value;
}
}
/// <remarks/>
public string city
{
get
{
return this.cityField;
}
set
{
this.cityField = value;
}
}
/// <remarks/>
public string stateOrProvince
{
get
{
return this.stateOrProvinceField;
}
set
{
this.stateOrProvinceField = value;
}
}
/// <remarks/>
public string postalCode
{
get
{
return this.postalCodeField;
}
set
{
this.postalCodeField = value;
}
}
/// <remarks/>
public string country
{
get
{
return this.countryField;
}
set
{
this.countryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryNationality
{
private int uidField;
private string countryField;
private bool mainEntryField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string country
{
get
{
return this.countryField;
}
set
{
this.countryField = value;
}
}
/// <remarks/>
public bool mainEntry
{
get
{
return this.mainEntryField;
}
set
{
this.mainEntryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryCitizenship
{
private int uidField;
private string countryField;
private bool mainEntryField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string country
{
get
{
return this.countryField;
}
set
{
this.countryField = value;
}
}
/// <remarks/>
public bool mainEntry
{
get
{
return this.mainEntryField;
}
set
{
this.mainEntryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryDateOfBirthItem
{
private int uidField;
private string dateOfBirthField;
private bool mainEntryField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string dateOfBirth
{
get
{
return this.dateOfBirthField;
}
set
{
this.dateOfBirthField = value;
}
}
/// <remarks/>
public bool mainEntry
{
get
{
return this.mainEntryField;
}
set
{
this.mainEntryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryPlaceOfBirthItem
{
private int uidField;
private string placeOfBirthField;
private bool mainEntryField;
/// <remarks/>
public int uid
{
get
{
return this.uidField;
}
set
{
this.uidField = value;
}
}
/// <remarks/>
public string placeOfBirth
{
get
{
return this.placeOfBirthField;
}
set
{
this.placeOfBirthField = value;
}
}
/// <remarks/>
public bool mainEntry
{
get
{
return this.mainEntryField;
}
set
{
this.mainEntryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/sdnList.xsd")]
public partial class sdnListSdnEntryVesselInfo
{
private string callSignField;
private string vesselTypeField;
private string vesselFlagField;
private string vesselOwnerField;
private int tonnageField;
private bool tonnageFieldSpecified;
private int grossRegisteredTonnageField;
private bool grossRegisteredTonnageFieldSpecified;
/// <remarks/>
public string callSign
{
get
{
return this.callSignField;
}
set
{
this.callSignField = value;
}
}
/// <remarks/>
public string vesselType
{
get
{
return this.vesselTypeField;
}
set
{
this.vesselTypeField = value;
}
}
/// <remarks/>
public string vesselFlag
{
get
{
return this.vesselFlagField;
}
set
{
this.vesselFlagField = value;
}
}
/// <remarks/>
public string vesselOwner
{
get
{
return this.vesselOwnerField;
}
set
{
this.vesselOwnerField = value;
}
}
/// <remarks/>
public int tonnage
{
get
{
return this.tonnageField;
}
set
{
this.tonnageField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool tonnageSpecified
{
get
{
return this.tonnageFieldSpecified;
}
set
{
this.tonnageFieldSpecified = value;
}
}
/// <remarks/>
public int grossRegisteredTonnage
{
get
{
return this.grossRegisteredTonnageField;
}
set
{
this.grossRegisteredTonnageField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool grossRegisteredTonnageSpecified
{
get
{
return this.grossRegisteredTonnageFieldSpecified;
}
set
{
this.grossRegisteredTonnageFieldSpecified = value;
}
}
}
My code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace Validus.New.Domain
{
class Testdeserialize
{
public void test()
{
sdnList sdnEntry = null;
string path = "D:/sdn1.xml";
XmlSerializer serializer = new XmlSerializer(typeof(sdnList));
StreamReader reader = new StreamReader(path);
sdnEntry = (sdnList)serializer.Deserialize(reader);
reader.Close();
}
}
}
But it doesn't work.
So how to deserialize this XML Document to C# class object ?
I dont think you have any issues with serializer/deserializer, rather you got problem here:
StreamReader reader = new StreamReader(path);
sdnEntry = (sdnList)serializer.Deserialize(reader);
reader.Close();
Try instead:
using(var fs = File.OpenRead(path))
{
sdnEntry = (sdnList)serializer.Deserialize(reader);
}

Categories