我添加了一個WCF服務參考使用此WSDL一個.NET項目: https://interop.cmiservices.org/axis/services/CAP1_1?wsdl爲什麼爲此WSDL生成的.NET代理會丟失一些數據?
它生成的代理類,等等,我能夠調用的方法。但是,在調用「getCAPAlerts」或「getCAPAlert」時,返回值似乎缺少數據。例如,'getCAPAlert'返回一個'alert'實例,但它的'info'屬性始終爲空。使用Fiddler,我可以檢查XML並查看從服務器返回的元素(請參見下文)。一個可能相關的註釋:'info'被定義爲0 .. wsdl中的'alert'不受限制,並且在代理中生成一個數組。此外,該行爲與使用WSE3的.net 2.0樣式的Web引用相同。
作爲一種解決方法,我編寫了自己的XML序列化(即實現IXmlSerializable)的類,並按預期方式反序列化(即info!= null)。但是,手寫這些文件很容易出錯,還有其他一些缺點。
爲什麼生成的代理類不能正確反序列化?糾正此問題的最佳方法是什麼?
SOAP響應:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:serverTime soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="http://dmi-services.org/CAP/1.0"></ns1:serverTime>
</soapenv:Header>
<soapenv:Body>
<ns2:getCAPAlertResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://dmi-services.org">
<getCAPAlertReturn>
<identifier>EINC171254539121009-6228</identifier>
<sender>[email protected]</sender>
<sent>2009-12-10T17:12:05</sent>
<status>Test</status>
<msgType>Alert</msgType>
<source xsi:nil="true"/>
<scope>Private</scope>
<restriction xsi:nil="true"/>
<addresses xsi:nil="true"/>
<code></code>
<note xsi:nil="true"/>
<references xsi:nil="true"/>
<incidents xsi:nil="true"/>
<info>
<language xsi:nil="true"/>
<category>Other</category>
<event>TEST TEST TEST Automobile Accident</event>
<urgency>Past</urgency>
<severity>Minor</severity>
<certainty>Unlikely</certainty>
<audience xsi:nil="true"/>
<effective xsi:nil="true"/>
<onset xsi:nil="true"/>
<expires xsi:nil="true"/>
<senderName>Customer Name</senderName>
<headline>TEST TEST FROM ETEAM INCIDENT</headline>
<description>desctiption</description>
<instruction xsi:nil="true"/>
<web xsi:nil="true"/>
<contact xsi:nil="true"/>
</info>
</getCAPAlertReturn>
</ns2:getCAPAlertResponse>
</soapenv:Body>
生成 '警報' 代理類:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="urn:oasis:names:tc:emergency:cap:1.1")]
public partial class Alert : object, System.ComponentModel.INotifyPropertyChanged {
private string identifierField;
private string senderField;
private string sentField;
private status statusField;
private msgType msgTypeField;
private string sourceField;
private System.Nullable<scope> scopeField;
private string restrictionField;
private string addressesField;
private string[] codeField;
private string noteField;
private string referencesField;
private string incidentsField;
private info[] infoField;
/// <remarks/>
public string identifier {
get {
return this.identifierField;
}
set {
this.identifierField = value;
this.RaisePropertyChanged("identifier");
}
}
/// <remarks/>
public string sender {
get {
return this.senderField;
}
set {
this.senderField = value;
this.RaisePropertyChanged("sender");
}
}
/// <remarks/>
public string sent {
get {
return this.sentField;
}
set {
this.sentField = value;
this.RaisePropertyChanged("sent");
}
}
/// <remarks/>
public status status {
get {
return this.statusField;
}
set {
this.statusField = value;
this.RaisePropertyChanged("status");
}
}
/// <remarks/>
public msgType msgType {
get {
return this.msgTypeField;
}
set {
this.msgTypeField = value;
this.RaisePropertyChanged("msgType");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string source {
get {
return this.sourceField;
}
set {
this.sourceField = value;
this.RaisePropertyChanged("source");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public System.Nullable<scope> scope {
get {
return this.scopeField;
}
set {
this.scopeField = value;
this.RaisePropertyChanged("scope");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string restriction {
get {
return this.restrictionField;
}
set {
this.restrictionField = value;
this.RaisePropertyChanged("restriction");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string addresses {
get {
return this.addressesField;
}
set {
this.addressesField = value;
this.RaisePropertyChanged("addresses");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string[] code {
get {
return this.codeField;
}
set {
this.codeField = value;
this.RaisePropertyChanged("code");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string note {
get {
return this.noteField;
}
set {
this.noteField = value;
this.RaisePropertyChanged("note");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string references {
get {
return this.referencesField;
}
set {
this.referencesField = value;
this.RaisePropertyChanged("references");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string incidents {
get {
return this.incidentsField;
}
set {
this.incidentsField = value;
this.RaisePropertyChanged("incidents");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public info[] info {
get {
return this.infoField;
}
set {
this.infoField = value;
this.RaisePropertyChanged("info");
}
}
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));
}
}
}
'info'屬性返回一個'info'對象的數組。信息對象/類是可序列化的嗎? – 2009-12-30 16:13:50
Web服務是您的,您可以調整wsdl xsd模式? – 2009-12-30 16:20:11
對不起,放棄這篇文章。信息也是由wsdl工具生成的,不幸的是,不,這不是我們控制的服務。拍的是正確的,這個來源沒有正確實現一個規範。此外,.net序列化與0 .. *元素有問題... – Daniel 2010-09-08 13:01:01