Scenario: WCF client app, calling a web-service (JAVA) operation, wich requires a complex object as parameter. Already got the metadata.
Problem: The operation has some required fields. One of them is a enum. In the SOAP sent, isnt the field above (generated metadata) - Im using WCF diagnostics and Windows Service Trace Viewer:
[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;
Property:
[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");
}
}
The enum:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="Person-Type", Namespace="http://webserviceX.or开发者_运维知识库g/")]
public enum PersonType {
/// <remarks/>
F,
/// <remarks/>
J,
}
Operation metadata:
[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;
}
}
The trace log:
<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>
When using the XML Serializer to serialize primitive types which have minOccurs="0"
in the XML Schema, there is an additional property added. It is named *Specified. In your case, I expect you have a boolean property named customerTypeSpecified
. You will need to set it to true
whenever you need the customerType
to be sent.
Simple question: if you instantiate the object normally and write it out to the console or System.Diagnostics.WriteLine explicitly using XmlSerializer, do you see the same behavior?
精彩评论