解决Web服务对象/实例

时间:2017-11-06 10:06:56

标签: c# xml web-services soap

发送请求后我收到此错误:

    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后无法找到电子邮件/电话类型。所以我不希望发送实际的主要联系方式时出现错误。

这是.ContactDetails:

的定义
    [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");
            }
        }
    }

如何添加此电话/电子邮件/传真类型?所以我实际上可以通过电子邮件/电话/传真发送请求。

由于

1 个答案:

答案 0 :(得分:1)

问题是我必须首先初始化它,然后填写如下的实例:

  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;

然后,当涉及将电子邮件包含在请求本身时,只需将其引用到您填写初始化后的所有详细信息的对象。