简体   繁体   English

如何将SOAP参数添加到C#服务参考

[英]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. 我已经在Visual Studio 2017根据客户端提供的WSDL创建了服务引用。 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. 我是SOAP服务的新手,无法弄清楚如何添加ActionCode。 I see it in the object browser and in the References.cs. 我在对象浏览器和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. 我对您使用的API一无所知。 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
        }            
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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