• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2011
  • Last Modified:

WCF Service doesn't recognize an XML element namespace when receiving a HTTP POST SOAP request

Hey everyone!

I have created an interface and implemented it as a WCF web service from a WSDL file I received from a 3rd party. A method on the server is supposed to be invoked by that 3rd party via a HTTP POST message, so I set the service binding property to basicHttpBinding.

Now, if I create a test client by adding a service reference to my service implementation, it works fine. However, when the SOAP message from the 3rd party is received, the method does get invoked, however the parameter that is supposed to get passed to it, is null.

I enabled WCF tracing in the web.config file and by analyzing the trace file, I found out it doesn't like the namespace of the parameter.

The error is:

Description      An unrecognized element was encountered in the XML during deserialization which was ignored.
Element      http://tempuri.org/XMLSchema.xsd:payload

Below is the relevant code and the XML/SOAP request that doesn't work as it should.

Any idea would be greatly appreciated.

Thanks,
Darko
[System.Web.Services.WebServiceBindingAttribute(Name = "CPServiceSoap", Namespace = "http://tempuri.org/")]
    [ServiceContract]
    public interface ICPServiceSoap
    {
        [System.Web.Services.WebMethodAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("SendCustomerRequest", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [OperationContract(IsOneWay = true, Action="http://tempuri.org/SendCustomerRequest")]
        void SendCustomerRequest([System.Xml.Serialization.XmlElementAttribute(Namespace = "http://tempuri.org/XMLSchema.xsd")] payload payload);
    }
 
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/XMLSchema.xsd")]
    [DataContract]
    public partial class payload
    {
        private MessageType messageField;
 
        [DataMember]
        public MessageType Message
        {
            get
            {
                return this.messageField;
            }
            set
            {
                this.messageField = value;
            }
        }
    }
 
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/XMLSchema.xsd")]
    [DataContract]
    public partial class MessageType
    {
 
        private string typeOfMessageField;
 
        private string dataField;
 
        [DataMember]
        public string TypeOfMessage
        {
            get
            {
                return this.typeOfMessageField;
            }
            set
            {
                this.typeOfMessageField = value;
            }
        }
 
        [DataMember]
        public string Data
        {
            get
            {
                return this.dataField;
            }
            set
            {
                this.dataField = value;
            }
        }
    }
 
 
 
/// Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <ns0:SendCustomerRequest xmlns:ns0="http://tempuri.org/">
      <ns1:payload xmlns:ns1="http://tempuri.org/XMLSchema.xsd">
        <ns1:Message>
          <ns1:TypeOfMessage>Text</ns1:TypeOfMessage>
          <ns1:Data>Jgam</ns1:Data>
        </ns1:Message>
      </ns1:payload>
    </ns0:SendCustomerRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window

0
DarkoLord
Asked:
DarkoLord
2 Solutions
 
topdog770Commented:
You may have already seen this link..
http://social.msdn.microsoft.com/Forums/en-US/biztalkr2adapters/thread/fc00a34f-2112-42ee-ac62-3bcc927c7887
But it outlines the basic detective track.
0
 
DarkoLordAuthor Commented:
Hi,

thanks for the link - I've seen it, though.

There were two problems, both solved now, fortunately.

The first one was the namespace, which was different for the Payload parameter - I had to add a "dummy" element with the correct namespace in order for it to work.

The second problem was that the order of the parameters was different from what WCF expected - I added the Order attribute to each of the parameters and it started working.

Cheers,
Darko
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now