开发者

XmlSerializer with Specified pattern not working

开发者 https://www.devze.com 2023-04-07 23:10 出处:网络
We\'re trying to consume a web service (Soap) and have generated an adapter for the schema using SvcUtil.exe.We have a field

We're trying to consume a web service (Soap) and have generated an adapter for the schema using SvcUtil.exe. We have a field

recurrenceCount

which should not be provided unless it has a value and so we have added a property

recurrenceCountSpecified

as according to MSDN . Even though recurrenceCountSpecified is false, the field recurrenceCount property is still specified in the outgoing xml.

What are we doing wrong ?

Adapter code :

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel","3.0.0.0")]  [System.ServiceModel.ServiceContractAttribute(Namespace="http://sas.elluminate.com/", ConfigurationName ="SASDefaultAdapterV2Port")] 
public interface SASDefaultAdapterV2Port 
{
     [System.ServiceModel.OperationContractAttribute(Action="http://sas.elluminate.com/setSession",ReplyAction = "*")]      
     [System.ServiceModel.FaultContractAttribute(typeof(sas.elluminate.com.ErrorResponse), Action = "http://sas.elluminate.com/setSession", Name="ErrorResponse")] 
     [System.ServiceModel.XmlSerializerFormatAttribute()]
     sessionResponseCollection setSession(setSessionRequest request); 
}

The modified class is :

[System.Diagnostics.DebuggerStepT开发者_JAVA技巧hroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel","3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="setSession", WrapperNamespace = "http://sas.elluminate.com/",IsWrapped = true)]
public partial class setSessionRequest
{

     [System.Xml.Serialization.XmlIgnoreAttribute()]       
     public bool recurrenceCountSpecified;

     [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://sas.elluminate.com/", Order = 19)]
     public int recurrenceCount;

}


The behavior you're attempting to use (xxxSpecified properties) does not apply if you're using a MessageContract. It applies only to the XmlSerializer. You have correctly specified that XmlSerializer should be used for the operation. However, because you have also specified that MessageContracts are to be used, the XmlSerializer only kicks in at the next level of serialization - i.e. when serializing each message member.

0

精彩评论

暂无评论...
验证码 换一张
取 消