2011-08-09 23 views
2

我使用貝寶助手http://paypalhelper.codeplex.com,並得到一個錯誤PayPal.Platform.SDK.FATALExceptionMVC貝寶助手錯誤:PayPal.Platform.SDK.FATALException

之後,我把源代碼也有看看正在發生的事情有後,我一個調試在測試項目public void TestImplicitSimplePay()的測試,並發現它是在類SoapEncoder的方法Decode排隊拋出一個錯誤96 return (object)serializer.Deserialize(reader);

public static object Decode(string soapEnvelope, Type toType) 
     { 
      XmlSerializer serializer = null; 

      try 
      { 
       /// Initializing the XMLSerializer. 
       serializer = new XmlSerializer(toType); 

       /// Removing SOAP outer Envelope 
       soapEnvelope = soapEnvelope.Replace("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body>", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("</soapenv:Body></soapenv:Envelope>", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("xmlns:ns2=\"http://svcs.paypal.com/types/ap\"", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("ns2:", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("soapenv:", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("ns3:", string.Empty); 
       soapEnvelope = soapEnvelope.Replace("xmlns:ns2=\"http://svcs.paypal.com/types/ap\"", string.Empty); 

       /// Deserializing and Returning the XML 
       using (MemoryStream reader = new MemoryStream(Encoding.UTF8.GetBytes(soapEnvelope))) 
       { 
        return (object)serializer.Deserialize(reader); //Error here 
       }     
      } 
      catch (FATALException) 
      { 
       throw; 
      } 
      catch (Exception ex) 
      { 
       throw new FATALException("Error occurred in SoapEncoder->Decode method", ex); 
      } 
      finally 
      { 
       serializer = null; 
      } 
     } 

的SoapEnvelope XML:

<xml version='1.0' encoding='utf-8'?> 
    <Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"> 
     <Header/> 
     <Body> 
      <PayResponse > 
       <responseEnvelope> 
        <timestamp>2011-08-09T00:28:53.399-07:00</timestamp> 
        <ack>Success</ack> 
        <correlationId>621854fd57929</correlationId> 
        <build>2012864</build> 
       </responseEnvelope> 
       <payKey>AP-1SE162159L922805T</payKey> 
       <paymentExecStatus>COMPLETED</paymentExecStatus> 
     </PayResponse> 

可能有人遇到這種情況,並知道我能做些什麼來解決這個問題?

回答

1

替換此行:

soapEnvelope = soapEnvelope.Replace("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body>", string.Empty); 

有了:

soapEnvelope = soapEnvelope.Replace("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body>", string.Empty); 

貝寶的迴應似乎略微改變和<soapenv:Header />節點不再有空間自行閉合的標籤之前結束。