0

I've added a SAP Netweaver service reference to my project using a local WSDL. The server returns a null response, but using Fiddler I can see the correct response is being sent. I assume this means the response isn't being deserialized correctly. This is how the root response element is defined in the WSDL:

<xsd:element name="adrl">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element ref="adr" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

The child element (some fields elided):

<xsd:element name="adr">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element ref="id"/>
        </xsd:sequence>
        <xsd:attribute name="op" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:NMTOKEN">
                    <xsd:enumeration value="update"/>
                    <xsd:enumeration value="delete"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>
</xsd:element>

Response:

<wsdl:output message="p1:p2.adrl"/>

Namespaces:

xmlns:p1="urn:mycompany:outbound"
xmlns:p2="http://tempuri.org/mycompany" 

SOAP response from service:

<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
    <SOAP:Header/>
    <SOAP:Body>
        <adrl>
            <adr op='update'>
                <id>9AF1FBA0-81A4-4427-A011-0DCE3BD1F609</id>
            </adr>
        </adrl>
    </SOAP:Body>
</SOAP:Envelope>

WCF class definitions (from Reference.cs):

// Some namespaces elided

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/mycompany")]
public partial class adr : object, System.ComponentModel.INotifyPropertyChanged {

    private string idField;

    // adrOP has a suitable enumeration defined elsewhere in the file
    private adrOP opField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string id {
        get {
            return this.idField;
        }
        set {
            this.idField = value;
            this.RaisePropertyChanged("id");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public adrOP op {
        get {
            return this.opField;
        }
        set {
            this.opField = value;
            this.RaisePropertyChanged("op");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class GetAdrResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/mycompany", Order=0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("adr", IsNullable=false)]
    public adr[] adrl;

    public GetAdrResponse() {
    }

    public GetAdrResponse(adr[] adrl) {
        this.adrl = adrl;
    }
}

When I try manually deserializing the response I captured in Fiddler (with adrl as the root element) I get the and Xml error with the inner exception message "" was not expected. If I add a root element to the serializer the error disappears, but only the "op" attribute is properly deserialized. The rest of the fields are null.

What could be the problem? I don't really have access to the Service but if there's something that has to change there I can forward a request. Otherwise I'm contemplating adding a MessageInspector and modifying the response, but I'm not really sure in which way it should be modified.

EDIT: I created the object in C# and deserialized it and this was the result:

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfAdr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <adr op="update">
    <id>9AF1FBA0-81A4-4427-A011-0DCE3BD1F609</id>
  </adr>
</ArrayOfAdr>

It seems like the root element is not properly defined in terms of serialization.

Community
  • 1
  • 1
ilitirit
  • 16,016
  • 18
  • 72
  • 111

1 Answers1

1

I had same problem when I tried to use WCF service in SAP Netweaver EJB DC. I solved this issue by adding XmlSerializerFormat tag to each operation in WCF Service and XmlRoot tag to the data contract:

    [XmlRoot(Namespace = "urn:sap.com:WS:Service1", ElementName = "Entity1")]
    [DataContract]
    public class Entity1
    {
    // your properties
    }

    [ServiceContract(Namespace = "urn:sap.com:WS:Service1", Name = "IService1")]
    public interface IService1
    {
        [XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        [OperationContract]
        Entity1 GetById(int id);

      [XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)] 
        [OperationContract]
        string Save(Entity1 entity);
    }

    [ServiceBehavior(Namespace = "urn:sap.com:WS:Service1", Name = "Service1")]
    [BindingNamespaceBehavior(bindingNamespace = "urn:sap.com:WS:Service1")]
    public class Service1 : IService1
    {
    Entity1 GetById(int id)
    {
        // your code
    }

    string Save(Entity1 entity)
    {
       // your code
    }
    }