2

Can someone help me understand why when I receive a soap envelope I don't receive all descendant nodes within the parent node when the receiving object serializes the soap body?

Contract interface class

    namespace AssemblyMDEPort
    {
        [ServiceContract(Name = "AssemblyMDEPort", Namespace = "urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0")]
        [XmlSerializerFormat]
        public interface IAssemblyMDEPort
        {
            [OperationContract(ReplyAction = "*", Action = "urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0/AssemblyMDEPort/NotifyCompleteRequest")]
            [XmlSerializerFormat(SupportFaults = true)]
            NotifyCompleteResponse NotifyReviewComplete(NotifyCompleteRequest request);
        }
    }

This is the client soap interface method that's executed when the soap envelope arrives at our service endpoint.

 public NotifyCompleteResponse NotifyReviewComplete(NotifyCompleteRequest request)

This is our SOAP object that handles serializing the incoming SOAP envelope.

[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class NotifyCompleteRequest  
{
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0", Order = 0)]
    public XElement NotifyCompleteRequestMessage;

    public NotifyFilingReviewCompleteRequest()
    {
    }
}

This is an example SOAP envelope sent into the service

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0">
       <soapenv:Header/>
       <soapenv:Body>
            <NotifyCompleteRequestMessage xmlns="urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0">
    <SendingMDELocationID xmlns="urn:oasis:names:tc:legalxml:schema:xsd:CommonTypes-4.0">
        <IdentificationID xmlns="http://niem.gov/niem/niem-core/2.0"></IdentificationID>
    </SendingMDELocationID>
                <SendingMDEProfileCode xmlns="urn:oasis:names:tc:legalxml:schema:xsd:CommonTypes-4.0">urn:oasis:names:tc:legalxml:schema:xsd:WebServicesMessaging-2.0</SendingMDEProfileCode>
                <ReviewCallbackMessage xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:ReviewFilingCallbackMessage-4.0" xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                    <nc:DocumentFiledDate>
                        <nc:DateTime>2018-06-07T13:55:56.0Z</nc:DateTime>
                    </nc:DocumentFiledDate>
                </ReviewCallbackMessage>
            </NotifyCompleteRequestMessage>         
       </soapenv:Body>
    </soapenv:Envelope>

The NotifyCompleteRequestMessage XElement attribute is only loaded w/ the first node and not all it's descendants like below and we need all the element nodes within the envelope body loaded within the NotifyCompleteRequestMessage attribute. There has to be a way to accomplish this.

<SendingMDELocationID xmlns="urn:oasis:names:tc:legalxml:schema:xsd:CommonTypes-4.0">
    <IdentificationID xmlns="http://niem.gov/niem/niem-core/2.0"></IdentificationID>
</SendingMDELocationID>
11
  • 1
    There is no namespace like soapenv on the node. So the attribute in square brackets above the object must have a namespace of "" (empty string). Commented Aug 12, 2019 at 22:55
  • Thanks for your help. Are you talking about this statement [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "urn:oasis:names:tc:legalxml-courtfiling:wsdl:WebServicesProfile-Definitions-4.0", Order = 0)] and setting the namespace to "". I tried that and now the NotifyCompleteRequestMessage = null, so nothing is loaded. Commented Aug 13, 2019 at 0:16
  • I indicated one tag that needed to be changed.More elements also need the change(or added brackets).You may also need to add [XmlRoot(ElementName = "ABC", Namespace = "")] above the class definition. XmlRoot can be used on any class (not just the first node).There are two different types of namespaces.One with a name like xmlns:soapenv= and the default namespace xmlns=.Sometimes the default namespace do not have an attribute when the brackets need just an empty string. Other times the default namespace like you have do have attributes.To debug create classes with sample data and serialize. Commented Aug 13, 2019 at 8:44
  • Ok Thanks. I was trying to avoid creating a bunch classes to serialize. All I want to do is load the complete xml body into an XElement that I can search using Linq for the information I need. I don't need each node serialized into it's own attribute. Is this possible. Ultimately, what I'm trying get is the data elements within the ReviewCallbackMessage, but it has more than 1 namespace. Does the MessageBodyMemberAttribute support using more than 1 namespace or maybe only is 1 needed for serializing. Not sure on this either. Commented Aug 13, 2019 at 13:54
  • Then avoid serializing. When I do not need all the info in xml I usually just use XML Linq (XDOCUMENT) to parse what I need. Commented Aug 13, 2019 at 14:09

1 Answer 1

1

The error may be due to the namespace nc not being defined. For testing a corrected the error. Try following :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);
            XElement notifyCompleteRequestMessage = doc.Descendants().Where(x => x.Name.LocalName == "NotifyCompleteRequestMessage").FirstOrDefault();
            XNamespace ns = notifyCompleteRequestMessage.GetDefaultNamespace();
            DateTime date = (DateTime)notifyCompleteRequestMessage.Descendants().Where(x => x.Name.LocalName == "DateTime").FirstOrDefault();
        }
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Hi jdweng, thanks, I actually just forgot to add the namespace nc to the node since I had to remove some confidential information when posting the question. I changed it in the above question and it was correct in my original code though. Regardless, I ran your xml example using .net fiddle and it works which you can see here dotnetfiddle.net/VcHlaw#, but how would I integrate the XDocument parse within my NotifyCompleteRequest serialize method that receives the XElement from the inbound SOAP message contract. Currently, I'm only getting the SendingMDELocationID node is all.
Do you need to serialize, or can you just parse with XDocument
No, I don't think I need to serialize. This service is using Mtom encoding though so the public NotifyReviewComplete(NotifyCompleteRequest request) method needs to return a specific response. But I think somehow I can change the NotifyReviewComplete method to except an XElement instead I believe, but I just get 500 errors when I do, so I think the interface class would need to change as well. If I can make this work without serializing that would be great. I posted what the actual contract interface looks like for the contract method. Thanks so much for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.