SOAP 请求中缺少参数

Parameter missing from SOAP request

我的服务请求一直有问题,我发现我的 'using' 语句隐藏了异常。我现在已经解决了这个问题,但我还有一个问题。我在 C# 中的参数分配没有进入 SOAP 请求。

这是我的 C#:

CharterServices.charterServiceClient proxy = new CharterServices.charterServiceClient();

// had problems with 'using' statements hiding exceptions. replace with try blocks
// http://msdn.microsoft.com/en-us/library/aa355056.aspx
try
{
    OperationContextScope scope = new OperationContextScope(proxy.InnerChannel);

    _ratesOfExchange = proxy.getRateOfExchange(new Service.getRateOfExchange()
    {
        charterEnquiryId = 1
    });

    proxy.Close();

    return _ratesOfExchange;
}

这是生成的请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <s:headerProperties>
         <brokerCode>1</brokerCode>
         <departmentId>503</departmentId>
         <language>en</language>
         <country>GB</country>
      </s:headerProperties>
   </s:Header>
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <getRateOfExchange xmlns="http://keepingitreal.co.uk"/>
   </s:Body>
</s:Envelope>

如您所见,getRateOfExchange 元素中缺少 charterEnquiryId parameter/attribute,导致服务返回错误。

为了完整起见,这里是服务引用生成的相关 类 片段。

// method
public ACS.CBS.BusinessDelegates.CharterServices.rateOfExchange[] getRateOfExchange(ACS.CBS.BusinessDelegates.CharterServices.getRateOfExchange getRateOfExchange1) {
    ACS.CBS.BusinessDelegates.CharterServices.getRateOfExchangeRequest inValue = new ACS.CBS.BusinessDelegates.CharterServices.getRateOfExchangeRequest();
    inValue.getRateOfExchange = getRateOfExchange1;
    ACS.CBS.BusinessDelegates.CharterServices.getRateOfExchangeResponse retVal = ((ACS.CBS.BusinessDelegates.CharterServices.charterService)(this)).getRateOfExchange(inValue);
    return retVal.getRateOfExchangeResponse1;
 }

// ...

// class
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://keepingitreal.co.uk")]
public partial class getRateOfExchange : object, System.ComponentModel.INotifyPropertyChanged {

private long charterEnquiryIdField;

private bool charterEnquiryIdFieldSpecified;

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public long charterEnquiryId {
            get {
                return this.charterEnquiryIdField;
            }
            set {
                this.charterEnquiryIdField = value;
                this.RaisePropertyChanged("charterEnquiryId");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool charterEnquiryIdSpecified {
            get {
                return this.charterEnquiryIdFieldSpecified;
            }
            set {
                this.charterEnquiryIdFieldSpecified = value;
                this.RaisePropertyChanged("charterEnquiryIdSpecified");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

我做错了什么?这两天我一直在尝试修复这个错误!

我认为您需要将 charterEnquiryIdSpecified 设置为 "tell" XML 序列化程序才能使用该值。