我正在尝试将Adyen定期付款实施到我的网络应用程序(C#.Net 4),但对于Web服务来说相对较新,我不确定我是否以正确的方式执行此操作。
简而言之,支付提供商为此目的公开了一个WSDL网址(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(object sender,System.EventArgs e)第38行C#
mscorlib.dll中出现'System.Threading.ThreadAbortException'类型的第一次机会异常 mscorlib.dll中出现“System.Threading.ThreadAbortException”类型的异常,但未在用户代码中处理 App_Web_4h0noljo.dll中发生了'System.NullReferenceException'类型的第一次机会异常 线程''(0x15d0)已退出,代码为0(0x0)。
答案 0 :(得分:1)
您的代码看起来不错。关键是将Recurring服务添加为 服务引用而不是Web引用。它应该工作,如果 app配置文件包含:
<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>
亲切的问候, 桑德拉斯克(Adyen)