【发布时间】:2015-01-12 17:47:41
【问题描述】:
我的服务请求一直存在问题,我发现我的“使用”语句一直在隐藏异常。我现在已经解决了这个问题,但我还有一个问题。我在 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 参数/属性,导致服务返回错误。
为了完整起见,这里是服务引用生成的相关类的 sn-ps。
// 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));
}
}
}
我做错了什么?我已经尝试修复这个错误两天了!
【问题讨论】:
-
与论坛网站不同,我们不使用“谢谢”、“任何帮助表示赞赏”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?.
-
好的,明白了。我以后会避开它们的。
-
WCF 类型的客户端是关于
using语句规则的例外。这是 WCF 设计中的一个缺陷。见“What is the best workaround for the WCF clientusingblock issue?”
标签: c# .net web-services wcf soap