简体   繁体   中英

How to add a SOAP parameter to a C# service reference

I have created service references in Visual Studio 2017 from WSDL 's provided by our client. One of them requires an attribute/parameter like:

<Item ActionCode="02">

I'm new to SOAP services and can't figure out how to add the ActionCode. I see it in the object browser and in the References.cs.

Here is my code so far (which works for a similar call with no attribute):

BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync req = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync()
{
    BasicMessageHeader = new BYDUpdateTimeSvc.BusinessDocumentBasicMessageHeader(),
    EmployeeTime = new BYDUpdateTimeSvc.EmployeeTimeCreateRequest()
    {
        EmployeeTimeAgreementItemUUID = new BYDUpdateTimeSvc.UUID { Value = rec.employeeTimeAgreement },
        Item = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem[1]
        {
            new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem()
            {
                TypeCode = activityCode,
                PaymentTypeCode = locationCode,
                EmployeeTimeValidity = _dateValidity
            }
        }
    }
};

How do I add that parameter/attribute?

I don't know anything about the API you are using. That said, have you tried setting the property using object initializer syntax.

BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync req = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync()
{
    BasicMessageHeader = new BYDUpdateTimeSvc.BusinessDocumentBasicMessageHeader(),
    EmployeeTime = new BYDUpdateTimeSvc.EmployeeTimeCreateRequest()
    {
        EmployeeTimeAgreementItemUUID = new BYDUpdateTimeSvc.UUID { Value = rec.employeeTimeAgreement },
        Item = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem[1]
        {
            new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem()
            {
                TypeCode = activityCode,
                PaymentTypeCode = locationCode,
                EmployeeTimeValidity = _dateValidity
            }, // added comma
            ActionCode = "02"; // set action code here
        }            
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM