Customize XML Serialize With new Tags And Attributes And Root

前端 未结 1 1528
南笙
南笙 2020-12-04 00:27

This is my Type:

public class MyObject {

    public string destAdd { get; set; }
    public long Time { get; set; }
    public int maxNumb { get; set; }
            


        
1条回答
  •  温柔的废话
    2020-12-04 00:45

    It appears that you are trying to call a web service, with a custom security header. Usually, the easiest way to do this would be to generate a set of proxy classes from the WSDL of the target webservice.

    Either

    • Right click on the use Add Service Reference / Add Web Reference from the Visual Studio
    • Or, if you have the WSDL and xsd files of the service, then use wsdl.exe command line tool (e.g. wsdl.exe *.wsdl *.xsd //language:c#)
    • See here on how to set security information on the ws:security header

    However, if you are 100% sure that you need to obtain the exact soapEnv Xml above, I would suggest you keep your code 'as is' (i.e. just serialize MyObject in its default format using XmlSerializer or DataContractSerializer), and then use a XslCompiledTransform.

    This XSLT will do exactly this:

    
    
        
        
            
                
                    
                        
                        
                    
                
                
                    
                        
                        
                        
                    
                
             
    
    

    Converts

    
    
      Destination
      
      99
      
        user
        pass
      
    
    

    To this:

    
    
      
        
          user
          pass
        
      
      
        
          Destination
          
          99
        
      
    
    

    0 讨论(0)
提交回复
热议问题