我的服务请求一直存在问题,并且发现“使用”语句隐藏了异常。我现在已经解决了这个问题,但是还有另一个问题。我在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参数/属性,导致服务返回错误。
为了完整起见,以下是由服务引用生成的相关类的摘要。
// 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
将XML Serializer设置为“告诉”使用该值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句