none
WCF SOAP Message RRS feed

  • Question

  • Hi all, I have to deploy a WCF web service to consume a SOAP Message sent from an external application

    This is the SOAP Message

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
                <S:Body>
                            <ns2:ConsOne xmlns:ns2="http://service.mydomain.com/">
                                       <dto>
                                                   <par1>xx</par1>

                                                   <par2>yy</par2>                                               
                                       </dto>
                            </ns2:ConsOne >
                </S:Body>
    </S:Envelope>

    I have develop my WCF Web service, but I can't consume the first message, I can only consume messages like this

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.mydomain.com/" xmlns:ns="http://schemas.datacontract.org/2004/07/">
       <soapenv:Header/>
       <soapenv:Body>
          <ser:ConsOne>
             <ser:dto>
                <par1>?</par1>
                <par2>?</par2>
             </ser:dto>
          </ser:ConsOne>
       </soapenv:Body>
    </soapenv:Envelope>

    as you can see de difference is in the node dto.

    thi is my code

    public class Service : IService
    {
    
        public string ConsOne (ConsOneDto dto)
        {
            if (dto == null)
                return "null";
            else
                return (System.DateTime.Now.ToLongTimeString());
        }
    
        public string ConsTwo(ConsTwoDto  dto)
        {
            return (System.DateTime.Now.ToLongTimeString());
        }
    
    
     
    }
    
    ...
    public class ConsOneDto
    {
            public string par1;
            public string par2;
            
            public ConsOneDto()
    	{
    		
    	}
    }

    Do you know how can I receive the first SOAP Message OK??
    Tuesday, May 14, 2013 6:56 PM

All replies

  • As you show in your sample messages the issue is down to namespacing of the dto node.  In one message it is xmlns="" and in the other it is xmlns="http://service.mydomain.com/".

    Depending on the contract definition, one of the messages is not correct.  I would either fix the external application to send in messages that conform to the schema definition OR you need to change your definition to accept both a dto without a namespace and a dto with a namespace.  To do this it will be a bit tricky to get the definition correct (as you have two objects with the same nodename) so I recommend exploring fixing the client first.


    Jeff

    Tuesday, May 14, 2013 10:26 PM
  • Hi, thanks for your response, the correct message is the first soap message, I have to develop a service that can be able to comsume.
    But my service can't parse the first message.

    Wednesday, May 15, 2013 11:42 AM
  • Ok, I understand.  What you need to do is decorate your ConsOneDto class with a blank namespace.

    [XmlRoot(Namespace="")] should do the trick.

    There are some resources out there, for example http://blogs.microsoft.co.il/blogs/rotemb/archive/2008/07/27/customize-your-net-object-xml-serialization-with-net-xml-attributes.aspx, but not as many as I thought there would.

    Let me know if this does not work and post your classes.  I can then update them so they match the first message.

    Cheers,

    Jeff



    Jeff

    Wednesday, May 15, 2013 9:42 PM
  • I put the XMLRoot attribute and nothing changes.

    My code

    /*IService.cs*/
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together.
    [ServiceContract(Namespace = "http://service.mydomain.com/")]
    public interface IService
    {
        [OperationContract ]
        string ConsOne(ConsOneDto dto);
    
        [OperationContract]
        string ConsTwo(ConsTwoDto dto);
    }
    
    /*Service.cs*/
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    
    public class Service : IService
    {
        public string ConsOne (ConsOneDto dto)
        {
            if (dto == null)
                return "null";
            else
                return (System.DateTime.Now.ToLongTimeString());
        }
    
        public string ConsTwo(ConsTwoDto  dto)
        {
            return (System.DateTime.Now.ToLongTimeString());
        }
    }
    
    
    /*ConsOneDto.cs*/
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    
    /// <summary>
    /// Summary description for ConsOneDto
    /// </summary>
    /// 
    [XmlRoot(Namespace = "")] 
    public class ConsOneDto
    {
            public string par1;
    
            public string par2;
            public string par22;
                   
    }

    Thursday, May 16, 2013 6:19 PM
  • Sorry MauroIvan; tried to get it to serialize correctly but could not find out how to influence the operation's parameter.  Frustrating as I feel I am missing something that I used to know how to do.

    The only other way this could be solved would be to extend WCF via a behavior that feels like an extreme approach.

    Maybe someone else has a suggestion?


    Jeff

    Friday, May 17, 2013 1:45 AM