serlingpa
serlingpa

Reputation: 12710

Parameter missing from SOAP request

I've been having problems with my service requests and I have discovered that my 'using' statements had been hiding exceptions. I have now fixed this but I have a further problem. My parameter assignments in C# are not making it in to the SOAP requests.

Here is my 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;
}

Here is the generated request:

<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>

As you can see, the charterEnquiryId parameter/attribute is missing from the getRateOfExchange element, resulting in the service returning a fault.

For completeness' sake, here are snippets of the relevant classes generated by the service reference.

// 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));
            }
        }
    }

What am I doing wrong? I've been trying to fix this one bug for two days now!

Upvotes: 1

Views: 1482

Answers (1)

Seymour
Seymour

Reputation: 7067

I think you need to set the charterEnquiryIdSpecified to "tell" the XML Serializer to use the value.

Upvotes: 2

Related Questions