【问题标题】:SOAP Fault vs HTTP 400SOAP 故障与 HTTP 400
【发布时间】:2017-10-05 10:34:54
【问题描述】:

如果我向服务器发送正确的 HTTP Post 请求,但包含错误的 SOAP 请求,是否有一些规范说明 Web 服务器是否应返回 HTTP 400(错误请求)或仅返回 SOAP 错误消息。在这种情况下,“一个错误的 SOAP 请求”意味着一个有效的 XML 文档,它不是以通常的 SOAP 元素三元组开头的:

<soapenv:Envelope>....
<soapenv:Header>...
<soapenv:Body>...

而是直接使用这样的 XML 元素:

<namespace:elem .....

【问题讨论】:

    标签: http soap put


    【解决方案1】:

    目前我找不到任何官方信息,根据经验,如果您的 XML 格式错误,则会收到 400 HTTP,如果 SOAP 消息中存在某种不正确的值,则会收到 SOAP 错误消息。

    要记住的一点是 HTTP 是 SOAP 服务使用的一种协议。如果需要,您可以通过 STMP(电子邮件)或其他协议运行 SOAP 服务。 HTTP 仅仅是传输。因此,不需要在标准文档中包含这些特定的 HTTP。 SOAP 术语中的 HTTP 400 意味着无法传递非常糟糕的消息。

    例如,像下面这样的格式错误的 xml 应该给出 HTTP 400:

     <nonsense>  <!-- opening tag with no closing tag-->
     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecol="http://www.blahblahablha">
     <soapenv:Header/>
        <soapenv:Body>
          <ecol:GetDatabaseConnectionInfo/>
       </soapenv:Body>
     </soapenv:Envelope>
    

    在下面的示例中,我的消息有一个 GUID,其值为 ?,这是一个错误,但是由于 XML 格式正确,因此消息在 SOAP 错误消息中返回。

     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ec="http://www.blahablha.au/foo" xmlns:irix="http://www.blahblah/IRIX_Headers_V1" xmlns:irix1="http://schemas.datacontract.org/2004/07/IRIXContract.MsgHeaderBase">
        <soapenv:Header/>
         <soapenv:Body>
          <ec:GetAccountActiveArrangement>
           <ec:GetAccountActiveArrangementReq>
             <irix:MsgReqHdr>
               <!--Optional:-->
               <irix:MsgGUID>?</irix:MsgGUID>
               <!--Optional:-->
               <irix:MsgDateTime>?</irix:MsgDateTime>
               <!--Optional:-->
               <irix:SecCredInfo>
                  <!--Optional:-->
                  <irix:IRIXUserID>?</irix:IRIXUserID>
                  <!--Optional:-->
                  <irix:IRIXPassword>?</irix:IRIXPassword>
                  <!--Optional:-->
                  <irix:AuthToken>?</irix:AuthToken>
                  <!--Optional:-->
                  <irix:ConsumerSystemID>?</irix:ConsumerSystemID>
               </irix:SecCredInfo>
            </irix:MsgReqHdr>
            <ec:accountNumber>70001</ecol:accountNumber>
    
      </ec:GetAccountActiveArrangement>
      </soapenv:Body>
    </soapenv:Envelope>
    

    发送这个会导致以下错误:

     <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:DeserializationFailed</faultcode>
            <faultstring xml:lang="en-AU">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://www.blah blah/ECollNXDB_V1:GetAccountActiveArrangementReq. The InnerException message was 'There was an error deserializing the object of type IRIXNXSoapServices.Message.Operations.Account.Get.GetAccountActiveArrangementReqV1. The value '?' cannot be parsed as the type 'Guid'.'.  Please see InnerException for more details.</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>
                     <HelpLink i:nil="true"/>
                     <InnerException>
                        <HelpLink i:nil="true"/>
                        <InnerException i:nil="true"/>
                        <Message>Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</Message>
    

    这是标准行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      相关资源
      最近更新 更多