2012-11-07 170 views
1

我想實施Adyen定期付款給我的Web應用程序(C#.Net 4),但是對於Web服務來說相對較新,我不確定我是否以正確的方式進行操作。Adyen與.Net的網絡服務訪問

總之,支付提供商爲此目的公開了一個WSDL URL(https://pal-test.adyen.com/pal/Recurring.wsdl),並將其作爲服務參考添加到Visual Studio 2010中(即添加服務參考>高級>添加Web引用)

然後我繼續創建一個測試頁,以確保連接可以運行(請參閱下面的代碼)並檢索我之前創建的測試訂閱的詳細信息。但是,當執行'listRecurringDetails'操作時出現異常,錯誤消息是'對象引用沒有設置爲對象的實例',我無法確定我要出錯的地方。

任何反饋將受到歡迎。

public partial class Store_ServiceTest : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     Recurring proxy = new Recurring(); 
     ICredentials usrCreds = new NetworkCredential("[username]", "[password]"); 
     proxy.Credentials = usrCreds; 

     try 
     { 
      RecurringDetailsRequest thisUserDetail = new RecurringDetailsRequest(); 
      thisUserDetail.merchantAccount = "[some reference]"; 
      thisUserDetail.shopperReference = "[some reference]"; 
      thisUserDetail.recurring.contract = "RECURRING"; 

      RecurringDetailsResult recContractDetails = proxy.listRecurringDetails(thisUserDetail); 
      string createDate = recContractDetails.creationDate.ToString(); 
     } 
     catch (Exception ex) 
     { 
      string err = ex.Message; 
     } 
     finally 
     { 
      proxy.Dispose(); 
     }   
    } 
} 
調用堆棧

App_Web_4h0noljo.dll!Store_ServiceTest.Page_Load(對象發件人,發送System.EventArgs)第38行C#

輸出窗口

類型「System.Threading.ThreadAbortException」的第一次機會異常出現在mscorlib.dll 類型「System.Threading.ThreadAbortException」的一個例外發生在mscorlib.dll但在用戶代碼 甲沒有處理在App_Web_4h0noljo.dll中發生類型'System.NullReferenceException'的第一次機會異常 線程''(0x15d0)已退出,並且代碼爲0(0x0)。

+1

什麼調試器說:如果 應用程序配置文件中包含它應該工作?請發佈堆棧跟蹤。 –

+0

嗨托馬斯。謝謝你的評論。調用堆棧似乎沒有顯示太多,所以我也添加了輸出窗口的內容。讓我知道你的想法。 Thx –

回答

1

你的代碼看起來不錯。關鍵是將週期性服務作爲 服務引用添加,而不是作爲Web引用。

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
     <binding name="AdyenHttpBinding"> 
      <security mode="Transport"> 
      <message clientCredentialType="UserName"/> 
      <transport clientCredentialType="Basic" realm="Adyen PAL Service Authentication"> <!--Adyen PAL Service Authentication--> 
       <extendedProtectionPolicy policyEnforcement="Never"/> 
      </transport> 
      </security> 
     </binding> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="https://pal-test.adyen.com/pal/servlet/soap/Payment" binding="basicHttpBinding" bindingConfiguration="AdyenHttpBinding" contract="Adyen.Payment.PaymentPortType" name="PaymentHttpPort"/> 
    <endpoint address="https://pal-test.adyen.com/pal/servlet/soap/Recurring" binding="basicHttpBinding" bindingConfiguration="AdyenHttpBinding" contract="Adyen.Recurring.RecurringPortType" name="RecurringHttpPort"/> 
</client> 
</system.serviceModel> 

親切的問候, 桑德Rasker(Adyen)

+0

謝謝你的幫助桑德。添加引用到web配置也是一個好的舉措! –

+0

有關thisUserDetail.recurring.contract =「RECURRING」的快速注意指出,這仍然產生'對象引用未設置爲對象的實例'錯誤,所以我爲您的建議thisUserDetail.recurring = new Adyen.Recurring( ){contract =「RECURRING」};並做了這項工作;-) –

+0

當我添加服務參考,它是要求一些用戶名和密碼。我如何獲得這些憑據 – kritikaTalwar