1

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!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
serlingpa
  • 12,024
  • 24
  • 80
  • 130
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Jan 12 '15 at 18:08
  • Ok, gotchya. I'll avoid them in the future. – serlingpa Jan 13 '15 at 11:17
  • WCF typed clients are the exception to the rule about `using` statements. This is a flaw in the design of WCF. See "[What is the best workaround for the WCF client `using` block issue?](http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue)" – John Saunders Jan 13 '15 at 12:45

1 Answers1

2

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

Seymour
  • 7,043
  • 12
  • 44
  • 51