SOAP web 服务在反序列化正文时抛出错误

SOAP webservice throws error when deserializing body

我正在尝试访问 SOAP 网络服务,但遇到了一个奇怪的错误:

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'

正如您从消息中看到的那样,它似乎达到了预期的效果?!

我怀疑这是一个namespace issueWSDL 和请求 SOAP 信封:

<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>

网络方法定义为:

List<CPID> GetCPIDs(Authenticate AuthObj);

其中 Authenicate 定义为:

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

如果是命名空间问题,欢迎任何指导

完整回复:

<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>

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

不是真的。命名空间 http://tempuri.org/ 和命名空间 http://tempuri.org 不同 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.