WCF Serialization problems with WSDL file created by Java tools

前端 未结 5 1239
甜味超标
甜味超标 2021-02-05 12:15

My team is tasked with getting several in-house developed .NET client applications to connect to some new Java web services. The Java web service is a third party, vendor suppli

相关标签:
5条回答
  • 2021-02-05 12:41

    I'm using an external "old" Java generated WSDL in my .Net Core app and the auto-generated Reference.cs did not work for me. I had to remove the [System.Xml.Serialization.XmlAttributeAttribute()] in order for it to work.

    0 讨论(0)
  • 2021-02-05 12:42

    Here is how to do Mikhail G's solution within IDE:

    • Open Reference.svcmap under Service References
    • Add <Wrapped>true</Wrapped> under <ClientOptions> and Save
    • Right Click Reference.svcmap and hit "Run Custom Tool"

    Visual Studio, where magic happens :)

    Note: Tried with VS 2015. Prior versions may have same option with a different name than "Run Custom Tool"

    0 讨论(0)
  • 2021-02-05 12:45

    Use svcutil.exe utility with the /wrapped option on to generate proxy classes.

    This will create slightly different classes then those created though Visual Studio in a way described by Ladislav Mrnka here. Resulting proxies should be free from the XmlAttribute issue when using on the client side.

    Example:

    svcutil /t:code wsdl.xml /out:wsdl.cs /serializer:XmlSerializer /wrapped
    
    0 讨论(0)
  • 2021-02-05 12:51

    As a follow-on to stratovarius's answer, in VS 2017 the Service References folder is replaced by Connected Services, so you have to:

    1. Open the {project}/Connected Services folder in Windows Explorer
    2. Find and edit the Reference.svcmap with a text editor
    3. Add <Wrapped>true</Wrapped> to the <ClientOptions> section
    4. Save the file
    5. In VS, right click on the service reference under Connected Services and select "Update Service Reference"

    This cleared the exception from my service call.

    0 讨论(0)
  • 2021-02-05 12:55

    Based on generated code it looks like your Java service expects request like:

    <s:Envelope xmlns:s="...">
      ...
      <s:Body>
        <QueryPBOT_MXWO_OS xmlns="http://www.ibm.com/maximo" baseLanguage="..." transLanguage="..." ...>
          <PBOT_MXWO_OSQuery>
            ...
          </PBOT_MXWO_OSQuery>
        </QueryPBOT_MXWO_OS>
      </s:Body>
    </s:Envelope>
    

    The problem is that WCF recognized QueryPBOT_MXWO_OS as wrapper element for request. I'm not sure why it fires exception but probably there is some restriction that wrapper element can't have attributes. I'm suspicious that this is just global error handling shared with version which uses IsWrapped=false where usage of attributes is error.

    You can try to modify your proxy in this way:

    [System.Diagnostics.DebuggerStepThroughAttribute()]        
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]        
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]        
    public partial class QueryPBOT_MXWO_OSRequest 
    { 
        [MessageBodyMemberAttribute(Name="QueryPBOT_MXWO_OS", Namespace="http://www.ibm.com/maximo")]
        public QueryPBOT_MXWO_OS QueryPBOT_MXWO_OS { get; set; }
    }  
    
    [XmlRoot(ElementName="QueryPBOT_MXWO_OS", Namespace="http://www.ibm.com/maximo")]
    public class QueryPBOT_MXWO_OS
    {
        [XmlElement(Namespace="http://www.ibm.com/maximo")]    
        public ConsoleApplication7.wsMaximo.PBOT_MXWO_OSQueryType PBOT_MXWO_OSQuery;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]           
        public string baseLanguage;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]         
        public string transLanguage;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]       
        public string messageID;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]       
        public string maximoVersion;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]       
        [System.ComponentModel.DefaultValueAttribute(false)]           
        public bool uniqueResult;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]      
        public string maxItems;           
    
        [XmlAttribute(Namespace="http://www.ibm.com/maximo")]           
        [System.ComponentModel.DefaultValueAttribute("0")]           
        public string rsStart;  
    }     
    
    0 讨论(0)
提交回复
热议问题