C# 使用C将数据保存到Workday Web服务时的XML序列化问题#

C# 使用C将数据保存到Workday Web服务时的XML序列化问题#,c#,xml,web-services,serialization,workday-api,C#,Xml,Web Services,Serialization,Workday Api,我正在使用以下WSDL并试图在Workday中保存 我遵循了workday API中提到的步骤(是在生成的源代码中删除[]和[]之后) 我面临以下问题。System.InvalidOperationException: '反映'提交\供应商\合同\修改\响应'的错误 InvalidOperationException:对于非数组类型,可以使用以下属性:XmlAttribute、XmlText、XmlElement或XmlAnyElement 这是源代码- Resource_Manage

我正在使用以下WSDL并试图在Workday中保存

我遵循了workday API中提到的步骤(是在生成的源代码中删除[]和[]之后)

我面临以下问题。System.InvalidOperationException:

'反映'提交\供应商\合同\修改\响应'的错误

InvalidOperationException:对于非数组类型,可以使用以下属性:XmlAttribute、XmlText、XmlElement或XmlAnyElement

这是源代码-

    Resource_ManagementPortClient hr = new Resource_ManagementPortClient();

    hr.Endpoint.Address = new EndpointAddress("https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v18/Resource_Management.wsdl");

    //Specify the username and password for WS-Security UsernameToken Header
    hr.ClientCredentials.UserName.UserName = "xxx";
    hr.ClientCredentials.UserName.Password = "xxx";

    CompanyObjectIDType[] cid = new CompanyObjectIDType[1];
    cid[0] = new CompanyObjectIDType { type = "Company_Reference_ID", Value = "327" };

    CurrencyObjectIDType[] currencyid = new CurrencyObjectIDType[1] { new CurrencyObjectIDType { type = "Currency_ID", Value = "USD" } };
    Supplier_Invoice_RequestObjectIDType[] supplerrid = new Supplier_Invoice_RequestObjectIDType[1] { new Supplier_Invoice_RequestObjectIDType { type = "Supplier_ID", Value = "S-0000006695" } };
    Payment_TermsObjectIDType[] paymentTerm = new Payment_TermsObjectIDType[1] { new Payment_TermsObjectIDType { type = "Payment_Terms_ID", Value = "NET0DAYS" } };

    Spend_CategoryObjectType catobjtype = new Spend_CategoryObjectType()
    {
        ID = new Spend_CategoryObjectIDType[]{ new Spend_CategoryObjectIDType {

                type="Spend_Category_ID",
                Value="SC0374"
            } }
    };

    Accounting_WorktagObjectType[] worktagobj =
        new Accounting_WorktagObjectType[]{ new Accounting_WorktagObjectType { ID= new Accounting_WorktagObjectIDType[] { new Accounting_WorktagObjectIDType {
                type="Cost_Center_Reference_ID",
                Value="W5310"

            } } } };


    Supplier_Invoice_DataType sisd = new Supplier_Invoice_DataType();

    sisd.Submit = true;
    sisd.Company_Reference = new CompanyObjectType() { ID = cid };
    sisd.Currency_Reference = new CurrencyObjectType() { ID = currencyid.ToArray() };
    sisd.Supplier_Invoice_Request_Reference = new Supplier_Invoice_RequestObjectType() { ID = supplerrid.ToArray() };
    sisd.Invoice_Date = DateTime.UtcNow;
    sisd.Suppliers_Invoice_Number = "SupplierInvoiceNumber000020";
    sisd.Payment_Terms_Reference = new Payment_TermsObjectType() { ID = paymentTerm.ToArray() };
    sisd.Invoice_Line_Replacement_Data = new Supplier_Invoice_Line_Replacement_DataType[] { new Supplier_Invoice_Line_Replacement_DataType {
            Extended_Amount=1234.56M,
            Spend_Category_Reference= catobjtype,
            Worktags_Reference = worktagobj

    } };

    //Instantiate Header for the request
    Workday_Common_HeaderType header = new Workday_Common_HeaderType();
    header.Include_Reference_Descriptors_In_Response = false;
    header.Include_Reference_Descriptors_In_ResponseSpecified = false;

    Submit_Supplier_Invoice_RequestType SSIR = new Submit_Supplier_Invoice_RequestType();
    //  SSIR.Business_Process_Parameters = new Financials_Business_Process_ParametersType() { Auto_Complete = false };
    SSIR.Supplier_Invoice_Data = sisd;
    SSIR.Business_Process_Parameters = new Financials_Business_Process_ParametersType() { Auto_Complete = false };


    Exceptions_Response_Data.
    try
    {
        var objres = hr.Submit_Supplier_Invoice(header, SSIR);
    }
    catch (Exception ex)
    {

        throw ex;
    }

}

xsd中有很多可选的定义

1) 在浏览器中转到以下网站:

2) 仅获取代码的架构部分并添加了所需的名称空间,因此我的xsd文件从以下内容开始:

<?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema elementFormDefault="qualified" attributeFormDefault="qualified"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:wd="urn:com.workday/bsvc"
                  targetNamespace="urn:com.workday/bsvc">
         <xsd:element name="Validation_Fault" type="wd:Validation_FaultType"/>
         <xsd:element name="Processing_Fault" type="wd:Processing_FaultType"/>
         <xsd:element name="Submit_Supplier_Invoice_Request"
                      type="wd:Submit_Supplier_Invoice_RequestType"/>

3) 然后我删除了模式定义之后的所有内容,因此结尾如下所示

               <xsd:element name="Calculated_Effort" minOccurs="0" maxOccurs="1">
                  <xsd:annotation>
                     <xsd:documentation>READ ONLY: Calculated effort for the assignment in the unit of time specified on the scenario.</xsd:documentation>
                  </xsd:annotation>
                  <xsd:simpleType>
                     <xsd:restriction base="xsd:decimal">
                       <xsd:totalDigits value="13"/>
                        <xsd:minInclusive value="0"/>
                        <xsd:fractionDigits value="3"/>
                     </xsd:restriction>
                  </xsd:simpleType>
               </xsd:element>
            </xsd:sequence>
         </xsd:complexType>
      </xsd:schema>

只读:以场景中指定的时间单位计算分配的工作量。
4) 将架构粘贴到workday.xsd文件中

5) 然后从cmd.exe使用xsd.exe实用程序,如下所示

.\xsd.exe-c-l:cs workday.xsd

6) 样品请求

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;


namespace ConsoleApplication143
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            //from sampleon following webpage
            //https://zappysys.com/blog/get-data-from-workday-in-ssis-using-soap-or-rest-api/
            //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bsvc="urn:com.workday/bsvc">
            //   <soapenv:Header/>
            //   <soapenv:Body>
            //      <bsvc:Employee_Get>
            //         <bsvc:Employee_Reference>
            //            <bsvc:Integration_ID_Reference>
            //               <bsvc:ID>gero et</bsvc:ID>
            //            </bsvc:Integration_ID_Reference>
            //         </bsvc:Employee_Reference>
            //      </bsvc:Employee_Get>
            //   </soapenv:Body>
            //</soapenv:Envelope>
            Envelope envelope = new Envelope()
            {
                header = new Header(),
                body = new Body()
                {
                    employee_Get = new Employee_Get()
                    {

                        employee_Reference = new Employee_Reference()
                        {
                            integration_ID_Reference = new Integration_ID_Reference()
                            {
                                ID = "gero et"
                            }
                        }
                    }
                }
            };

            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add("bsvc", "urn:com.workday/bsvc");
            namespaces.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(FILENAME, settings);

            XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
            serializer.Serialize(writer, envelope, namespaces);

        }
    }

    [XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Envelope
    {
        [XmlElement(ElementName = "Header", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public Header header { get; set; }
        [XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public Body body { get; set; }
    }
    [XmlRoot(ElementName = "Header", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Header
    {
    }
    [XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Body
    {
        [XmlElement(ElementName = "Employee_Get", Namespace = "urn:com.workday/bsvc")]
        public Employee_Get employee_Get { get; set; }
    }
    [XmlRoot(ElementName = "Employee_Get", Namespace = "urn:com.workday/bsvc")]
    public class Employee_Get
    {
        [XmlElement(ElementName = "Employee_Reference", Namespace = "urn:com.workday/bsvc")]
        public Employee_Reference employee_Reference { get; set; }
    }
    [XmlRoot(ElementName = "Employee_Reference", Namespace = "urn:com.workday/bsvc")]
    public class Employee_Reference
    {
        [XmlElement(ElementName = "Integration_ID_Reference", Namespace = "urn:com.workday/bsvc")]
        public Integration_ID_Reference integration_ID_Reference { get; set; }
    }
    [XmlRoot(ElementName = "Integration_ID_Reference", Namespace = "urn:com.workday/bsvc")]
    public class Integration_ID_Reference
    {
        [XmlElement(ElementName = "ID", Namespace = "urn:com.workday/bsvc")]
        public string ID { get; set; }
    }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Serialization;
命名空间控制台应用程序143
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
//来自以下网页的样本
//https://zappysys.com/blog/get-data-from-workday-in-ssis-using-soap-or-rest-api/
//
//   
//   
//      
//         
//            
//杰罗等人
//            
//         
//      
//   
//
信封信封=新信封()
{
header=新的header(),
body=新body()
{
员工获取=新员工获取()
{
员工参考=新员工参考()
{
集成\u ID\u引用=新集成\u ID\u引用()
{
ID=“gero et”
}
}
}
}
};
XmlSerializerNamespaces=新的XmlSerializerNamespaces();
namespace.Add(“bsvc”,“urn:com.workday/bsvc”);
名称空间。添加(“soapenv”http://schemas.xmlsoap.org/soap/envelope/");
XmlWriterSettings=新的XmlWriterSettings();
settings.Indent=true;
XmlWriter=XmlWriter.Create(文件名、设置);
XmlSerializer serializer=新的XmlSerializer(typeof(信封));
序列化(编写器、信封、名称空间);
}
}
[XmlRoot(ElementName=“信封”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共类信封
{
[XmlElement(ElementName=“Header”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共标头{get;set;}
[XmlElement(ElementName=“Body”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共机构主体{get;set;}
}
[XmlRoot(ElementName=“Header”,名称空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共类标题
{
}
[XmlRoot(ElementName=“Body”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共阶级团体
{
[xmlement(ElementName=“Employee_Get”,Namespace=“urn:com.workday/bsvc”)]
公共雇员\u Get雇员\u Get{Get;set;}
}
[XmlRoot(ElementName=“Employee_Get”,Namespace=“urn:com.workday/bsvc”)]
公共类雇员
{
[xmlement(ElementName=“Employee_Reference”,Namespace=“urn:com.workday/bsvc”)]
公共雇员\参考雇员\参考{get;set;}
}
[XmlRoot(ElementName=“Employee_Reference”,Namespace=“urn:com.workday/bsvc”)]
公共类员工参考
{
[xmlement(ElementName=“集成ID\u引用”,Namespace=“urn:com.workday/bsvc”)]
公共集成\u ID\u引用集成\u ID\u引用{get;set;}
}
[XmlRoot(ElementName=“Integration\u ID\u Reference”,Namespace=“urn:com.workday/bsvc”)]
公共类集成\u ID\u引用
{
[xmlement(ElementName=“ID”,Namespace=“urn:com.workday/bsvc”)]
公共字符串ID{get;set;}
}

@jdweng谢谢你的回答。你能帮我提供更多信息吗..我正在使用WSDL..我希望生成的代码中有问题..我现在对XSD感到困惑。如果可能的话,如果你能提供任何示例代码..非常感谢你的帮助..如果你可以参考,我已经上传了代码..我更新了代码。请参阅网页: