I am building a Soap Body for a web-service, and there are dozens of optional fields.
Currently I have been handling these like this:
wsSoapBody.OrderType = aMessage[(int)cardCreate.OrderType].ToString();
wsSoapBody.ActivateFlag = Convert.ToInt32(aMessage[(int)cardCreate.ActivateFlag].ToString()); //P-02925;
if (aMessage[(int)cardCreate.ShipDate].ToString() != ""){
wsSoapBody.ShipmentDate = Convert.ToDateTime(aMessage[(int)cardCreate.ShipDate].ToString()); //P-02925;
}
wsSoapBody.ShipmentMethodCard = aMessage[(int)cardCreate.ShipMethodCard].ToString();
wsSoapBody.ShipmentMethodPin = aMessage[(int)cardCreate.ShipMethodPIN].ToString();
The CardCreate you see in those value assignments is an enumerated constant in the class cardCreate defined as below:
namespace EvryCardManagement
{
class CardCreate
{
#region Variables
private DCSSCardCreateType req;
private DCSSCardCreateResponseType rsp;
private DCSSCardCreate_V3_0Service stub;
public string tokenID { get; set; }
private enum cardCreate
{
MsgType = 0,
MsgVersion = 1,
WSName = 2,
ReplyTo = 3,
SourceSystem = 4,
Timestamp = 5,
UniqueMessageID = 6,
SFDCContext = 7,
InstitutionID = 8,
CardNumber = 9,
Version = 10,
ProductID = 11,
AccountNumber = 12,
CustomerID = 13,
CustomerNumber = 14,
EmbossName1 = 15,
Expiry = 16,
FeeMonth = 17,
ChargeAccountNo = 18,
PINMethod = 19,
CardFlag = 20,
AddressTypeCard = 21,
AddressTypePIN = 22,
OrderType = 23,
ActivateFlag = 24,
ShipDate = 25,
ShipMethodCard = 26,
ShipMethodPIN = 27,
FirstName = 28,
LastName = 29,
CardAddress1 = 30,
CardAddress2 = 31,
CardAddress3 = 32,
CardAddress4 = 33,
CardAddress5 = 34,
CardAddress6 = 35,
CardPostCode = 36,
CardCity = 37,
CardCountry = 38,
PINName = 39,
PINAddress1 = 40,
PINAddress2 = 41,
PINAddress3 = 42,
PINAddress4 = 43,
PINAddress5 = 44,
PINAddress6 = 45,
PINPostCode = 46,
PINCity = 47,
PINCountry = 48,
Validfrom = 49,
Note = 50,
MakeCheckStatus = 51,
EmbossName2 = 52,
PAmount = 53,
PAmountLength = 54,
GKIndicator = 55,
CreditLimit = 56,
CardDesignNo = 57,
ExtPictureID = 58,
BulkID = 59,
AccountNo2 = 60
}
so, rather than doing them all one by one as I have been doing, is it possible to loop through the wsSoapBody (which is defined in the web-service) and for each one, get the corresponding value from the aMessage (which is defined as an array like this string[] aMessage)
EDIT
I have the below code to loop through, but I want to assign to the wsSoapBody and I am stuck:
foreach (cardCreate cItem in (cardCreate[])Enum.GetValues(typeof(cardCreate)))
{
}
(the above correction was suggested as an edit by Steve Lillis that was rejected due to a conflict)
so I don't know how then to assign the values to each element for example I want to set
wsSoapBody[cItem].value = aMessage[(int)CardCreate[cItem]`
or I also tried:
wsSoapBody[cItem] = aMessage[(int)cItem].ToString();
but am having trouble making it work (or even compile) due to lack of knowledge
EDIT #2:
I have also looked at GetNames as possibly I want the names and tried:
foreach (string name in Enum.GetNames(typeof(cardCreate)))
{
wsSoapBody[name] = aMessage[(int)name].ToString();
}
But I cannot apply indexing with [] to an expression of type 'DCSSCardCreateType'
thanks