我正在使用以下WSDL并尝试在Workday中保存
https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v18/Resource_Management.wsdl。
我已经按照工作日API(https://community.workday.com/articles/946(中提到的步骤进行操作。那是在生成的源代码中使用 [] 删除 [][] 之后。
我面临以下问题。System.InvalidOperationException:
"有一个错误反映了'Submit_Supplier_Contract_Amendment_Response
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(在浏览器中访问以下网站:https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v18/Resource_Management.wsdl
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( 然后使用 xsd.exe 实用程序,如下所示 cmd.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:temptest.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; }
}