场景:WCF客户端应用程序,调用Web服务(JAVA)操作,需要复杂对象作为参数。已经获得了元数据。
问题:该操作有一些必填字段。其中一个是枚举。在发送的SOAP中,不是上面的字段(生成的元数据) - 我正在使用WCF诊断和Windows服务跟踪查看器:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="Consult-Filter", Namespace="http://webserviceX.org/")]
public partial class ConsFilter : object, System.ComponentModel.INotifyPropertyChanged {
private PersonType customerTypeField;
属性:
[System.Xml.Serialization.XmlElementAttribute("customer-type", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public PersonType customerType {
get {
return this.customerTypeField;
}
set {
this.customerTypeField = value;
this.RaisePropertyChanged("customerType");
}
}
枚举:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="Person-Type", Namespace="http://webserviceX.org/")]
public enum PersonType {
/// <remarks/>
F,
/// <remarks/>
J,
}
操作元数据:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class consultRequest {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://webserviceX.org/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public ServiceClient.ConsultServiceReference.ConsFilter filter;
public consultRequest() {
}
public consultRequest(ServiceClient.ConsultServiceReference.ConsFilter filter) {
this.filter = filter;
}
}
跟踪日志:
<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<VsDebuggerCausalityData>data</VsDebuggerCausalityData>
</WebHeaders>
</HttpRequest>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"></Action>
<ActivityId CorrelationId="correlationId" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">activityId</ActivityId>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<filter xmlns="http://webserviceX.org/">
<product-code xmlns="">116</product-code>
<customer-doc xmlns="">777777777</customer-doc>
</filter>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>
答案 0 :(得分:1)
使用XML Serializer序列化XML Schema中具有minOccurs="0"
的基本类型时,会添加一个附加属性。它被命名为* Specified。在您的情况下,我希望您有一个名为customerTypeSpecified
的布尔属性。无论何时需要发送true
,您都需要将其设置为customerType
。
答案 1 :(得分:0)
简单问题:如果你正常实例化对象并使用XmlSerializer明确地将其写入控制台或System.Diagnostics.WriteLine,你会看到相同的行为吗?