Search code examples
soapruntime-errordeserialization

SOAP webservice throws error when deserializing body


I am trying to hit a SOAP webservice but encounter an odd error:

Error in deserializing body of request message for operation 'GetCPIDs'. OperationFormatter encountered an invalid Message body. 

Expected to find node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org/'. 
Found node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org'

As you can see from the message, it appears to be getting exactly what it is expected?!

I suspect this is a namespace issue. The WSDL, and the request SOAP envelope:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://tempuri.org">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <GetCPIDs xmlns:tns="https://webservice.codeproof.com/public/v1/CodeproofService.svc" tns:GetCPIDs="http://schemas.datacontract.org/2004/07/Codeproof.External.Webservice">
      <Authenticate xmlns:type="http://schemas.microsoft.com/2003/10/Serialization/" type:xsi="http://schemas.datacontract.org/2004/07/Codeproof.External.Webservice">
        <userid type:xsi="xsd:string">REDACTED</userid>
        <apikey type:xsi="xsd:string">REDACTED</apikey>
      </Authenticate>
    </GetCPIDs>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The web method definition is:

List<CPID> GetCPIDs(Authenticate AuthObj);

Where Authenicate is defined as:

public class Authenticate
 {
 public string userid { get; set; }
 public string apikey { get; set; }
 }

If a namespace issue, any guidance is appreciated.

The full response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
      <faultstring xml:lang="en-US">Error in deserializing body of request message for operation 'GetCPIDs'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org'</faultstring>
      <detail>
        <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <HelpLink i:nil="true"/>
          <InnerException>
            <HelpLink i:nil="true"/>
            <InnerException i:nil="true"/>
            <Message>OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org'</Message>
            <StackTrace>   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)</StackTrace>
            <Type>System.Runtime.Serialization.SerializationException</Type>
          </InnerException>
          <Message>Error in deserializing body of request message for operation 'GetCPIDs'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetCPIDs' and namespace 'http://tempuri.org'</Message>
          <StackTrace>   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
          <Type>System.ServiceModel.CommunicationException</Type>
        </ExceptionDetail>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

Solution

  • As you can see from the message, it appears to be getting exactly what it is expected?!

    Not really. Namespace http://tempuri.org/ and namespace http://tempuri.org are different because of the trailing /.

    URI references identifying namespaces are compared when determining whether a name belongs to a given namespace, and whether two names belong to the same namespace. [Definition: The two URIs are treated as strings, and they are identical if and only if the strings are identical, that is, if they are the same sequence of characters. ] The comparison is case-sensitive, and no %-escaping is done or undone.