Search code examples
c#wcf

Service expects namespace of tempuri.org


I have a WCF service which is receiving a message from a BizTalk server.

This message that's being processed by the BT server is simply being picked up from an FTP folder and sent over to an operation on the service which is defined as follows:

[OperationContract(Action="http://www.mysite.com/ConvertAA", 
                   Name="AA", IsOneWay=false)]
void SaveDataFromAA(AA receivedDoc);

When this message arrives however, I get a message that:

Error in deserializing body of request message for operation 'AA'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'AA' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'AA' and namespace ''

Now this is because the xml sent by the third party (I have no control over this) looks like this:

<?xml version="1.0" standalone="yes"?>
<AA>
    <AAData>...</AAData>
</AA>

I have their schema already in my project and when I try to call SaveDataFromAA I get the error above.

I tried using a blank namespace on my service contract but that still looks for tempuri.org - I don't have the control over their xml so is there a way I can intercept it, alter it and handle it accordingly? I'd be happy to wrap it but I'm not too sure where to start.


Solution

  • I am pretty sure you need to modify your AA class (receivedDoc parameter) to something similar to the following:

    [DataContract]
    public class AA 
    {
       [DataMember]
       public string AAData {get; set;}
    }
    

    or assuming none of your properties or classes match then:

    [DataContract(Name="AA")]
    public class SomeOtherName
    {
       [DataMember(Name="AAData")]
       public string SomeOtherProperty {get; set;}
    }
    

    You can find more information including how to set namespace information for the data contracts at the following location:

    http://msdn.microsoft.com/en-us/library/ms733127(v=vs.110).aspx

    The data contract equivalence is probably worth reviewing in more detail

    http://msdn.microsoft.com/en-us/library/ms734767(v=vs.110).aspx