Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
i'm not able to supply parameter for following response list structure pls advise how it can be achived

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <SupplyCancelServiceRequest xmlns="http://dtts.sfda.gov.sa/SupplyCancelService">
            <PRODUCTLIST xmlns="">
                <PRODUCT>
                    <GTIN>[string]</GTIN>
                    <SN>[string]</SN>
                    <BN>[string?]</BN>
                    <XD>[date?]</XD>
                </PRODUCT>
            </PRODUCTLIST>
        </SupplyCancelServiceRequest>
    </Body>
</Envelope>


What I have tried:

C#
   Supcancel.supplyCancelServiceRequest sup = new Supcancel.supplyCancelServiceRequest();


   Supcancel.product prd = new Supcancel.product();
   prd.BN = "004";
   prd.GTIN = "06102030405089";
   prd.SN = "29091576";
   prd.XD = xd_date;

sup.PRODUCTLIST[0].BN = "004";
sup.PRODUCTLIST[1].GTIN = "06102030405089";
sup.PRODUCTLIST[2].SN = "29091576";
sup.PRODUCTLIST[3].XD = xd_date;


   var cn = cclient.notifySupplyCancel(sup);
Posted
Updated 30-Sep-19 9:20am
v2

1 solution

If we translate your xml request to C# then we get something like below

C#
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace YourNameSpace
{
	[XmlRoot(ElementName="PRODUCT")]
	public class PRODUCT {
		[XmlElement(ElementName="GTIN")]
		public string GTIN { get; set; }
		[XmlElement(ElementName="SN")]
		public string SN { get; set; }
		[XmlElement(ElementName="BN")]
		public string BN { get; set; }
		[XmlElement(ElementName="XD")]
		public string XD { get; set; }
	}

	[XmlRoot(ElementName="PRODUCTLIST")]
	public class PRODUCTLIST {
		[XmlElement(ElementName="PRODUCT")]
		public PRODUCT PRODUCT { get; set; }
		[XmlAttribute(AttributeName="xmlns")]
		public string Xmlns { get; set; }
	}

	[XmlRoot(ElementName="SupplyCancelServiceRequest", Namespace="http://dtts.sfda.gov.sa/SupplyCancelService")]
	public class SupplyCancelServiceRequest {
		[XmlElement(ElementName="PRODUCTLIST")]
		public PRODUCTLIST PRODUCTLIST { get; set; }
		[XmlAttribute(AttributeName="xmlns")]
		public string Xmlns { get; set; }
	}

	[XmlRoot(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
	public class Body {
		[XmlElement(ElementName="SupplyCancelServiceRequest", Namespace="http://dtts.sfda.gov.sa/SupplyCancelService")]
		public SupplyCancelServiceRequest SupplyCancelServiceRequest { get; set; }
	}

	[XmlRoot(ElementName="Envelope", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
	public class Envelope {
		[XmlElement(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
		public Body Body { get; set; }
		[XmlAttribute(AttributeName="xmlns")]
		public string Xmlns { get; set; }
	}

}


You can create your request something like this

C#
var request = new Envelope()
{
     Body = new Body()
     {
	SupplyCancelServiceRequest = new SupplyCancelServiceRequest()
	{
		PRODUCTLIST = new PRODUCTLIST()
		{
			PRODUCT = new List<PRODUCT>()
			{
				new PRODUCT()
				{
					BN = "1",
	  		                GTIN = "1",
					SN = "1",
				},
				new PRODUCT()
				{
					BN="2",
					GTIN="2",
					SN="2",
				}
			}
		}
	}
    }
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900