发送请求后收到此错误:
System.ServiceModel.FaultException`1[FinancierAPITester.SITCustomerServiceReference.ApiError]: Unable to process the request as an attempt was made to create an abstract class. (Fault Detail is equal to FinancierAPITester.SITCustomerServiceReference.ApiError).
发送此请求时:
//MessageBox.Show("Running Add Contact Details Test!");
CustomerServiceClient customerServiceClient = new CustomerServiceClient();
AddContactDetailRequest addContactDetailsRequest = new AddContactDetailRequest();
AddContactDetailResponse addContactDetailsResponse = new AddContactDetailResponse();
addContactDetailsRequest.ContactDetails = new SITCustomerServiceReference.ContactDetail();
addContactDetailsRequest.UserName = "username";
addContactDetailsRequest.Password = "password";
addContactDetailsRequest.SystemToken = systemToken;
addContactDetailsRequest.CustomerNumber = "customerNumber";
addContactDetailsRequest.ContactDetails.SequenceNumber = 1;
在 SOAP UI 中,请求可以像这样工作 (XML):
<ns:AddContactDetail>
<!--Optional:-->
<ns:request>
<!--Optional:-->
<data:AccessToken/>
<!--Optional:-->
<data:Password>${#Project#password}</data:Password>
<!--Optional:-->
<data:ProcessId/>
<!--Optional:-->
<data:SystemToken>${#Project#systemToken}</data:SystemToken>
<!--Optional:-->
<data:UserName>${#Project#username}</data:UserName>
<!--Optional:-->
<data:ContactDetails xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="data:Phone">
<data:FinancierContactDetail i:nil="true"/>
<data:FinancierLocationCode i:nil="true"/>
<data:FinancierTypeCode i:nil="true"/>
<data:SequenceNumber>1</data:SequenceNumber>
<data:Number>${#TestCase#phoneNumber}</data:Number>
<data:PhoneType>${#TestCase#phoneType}</data:PhoneType>
<data:UserId i:nil="true"/>
</data:ContactDetails>
<!--Optional:-->
<data:CustomerNumber>00100000000</data:CustomerNumber>
</ns:request>
</ns:AddContactDetail>
对我来说,主要问题是输入addContactDetailsRequest.ContactDetails后找不到电子邮件/电话类型。 所以 Obv 我希望在不发送实际的主要联系方式时出现错误。
这是 的定义。联系方式:
[System.Runtime.Serialization.DataMemberAttribute()]
public FinancierAPITester.SITCustomerServiceReference.ContactDetail ContactDetails {
get {
return this.ContactDetailsField;
}
set {
if ((object.ReferenceEquals(this.ContactDetailsField, value) != true)) {
this.ContactDetailsField = value;
this.RaisePropertyChanged("ContactDetails");
}
}
}
更多定义,如果它们有帮助:
[System.Diagnostics.DebuggerStepThroughAttribute()[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ContactDetail", Namespace="URL")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Fax))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Email))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Phone))]
public partial class ContactDetail : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.Nullable<int> SequenceNumberField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Nullable<int> SequenceNumber {
get {
return this.SequenceNumberField;
}
set {
if ((this.SequenceNumberField.Equals(value) != true)) {
this.SequenceNumberField = value;
this.RaisePropertyChanged("SequenceNumber");
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Email", Namespace="http://financier.api.welcom.co.uk/2016/10/data")]
[System.SerializableAttribute()]
public partial class Email : FinancierAPITester.SITCustomerServiceReference.ContactDetail {
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.DateTime DateDeletedField;
private string EmailAddressField;
private FinancierAPITester.SITCustomerServiceReference.EmailType EmailTypeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string UserIdField;
[System.Runtime.Serialization.DataMemberAttribute()]
public System.DateTime DateDeleted {
get {
return this.DateDeletedField;
}
set {
if ((this.DateDeletedField.Equals(value) != true)) {
this.DateDeletedField = value;
this.RaisePropertyChanged("DateDeleted");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string EmailAddress {
get {
return this.EmailAddressField;
}
set {
if ((object.ReferenceEquals(this.EmailAddressField, value) != true)) {
this.EmailAddressField = value;
this.RaisePropertyChanged("EmailAddress");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public FinancierAPITester.SITCustomerServiceReference.EmailType EmailType {
get {
return this.EmailTypeField;
}
set {
if ((this.EmailTypeField.Equals(value) != true)) {
this.EmailTypeField = value;
this.RaisePropertyChanged("EmailType");
}
}
}
如何添加此电话/电子邮件/传真类型?因此,我实际上可以通过电子邮件/电话/传真发送请求。
谢谢
问题是我必须先初始化它,然后填写如下所示的实例:
addContactDetailsRequest.ContactDetails = new SITCustomerServiceReference.Phone();
SITCustomerServiceReference.Phone phoneContactDetails = new Phone();
phoneContactDetails.Number = "01772444444";
phoneContactDetails.PhoneType = SITCustomerServiceReference.PhoneType.Home;
string currentDateString = "2017/06/11T00:00:00";
DateTime currentDate = Convert.ToDateTime(currentDateString);
phoneContactDetails.DateDeleted = currentDate;
addContactDetailsRequest.UserName = "UserName ";
addContactDetailsRequest.Password = "Password ";
addContactDetailsRequest.SystemToken = systemToken;
addContactDetailsRequest.CustomerNumber = "00123456789";
addContactDetailsRequest.ContactDetails.SequenceNumber = 1;
addContactDetailsRequest.ContactDetails = phoneContactDetails;
然后,当涉及到将电子邮件包含在请求本身中时,只需将其引用添加到您在初始化后填写所有详细信息的对象。