PayPal SOAP API响应需要手动解析 [英] PayPal SOAP API reponses require manual parsing

查看:111
本文介绍了PayPal SOAP API响应需要手动解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个网络项目,其中包括将PayPal的Express Checkout实施为付款服务.该项目使用C#,我使用的是Visual Studio 2010和PayPal API的SOAP版本.我正在使用的API版本是91.0(尝试将其切换到其他版本,但问题仍然存在),我正在沙盒中进行开发.

I am currently working on a web project that includes implementing PayPal's Express Checkout as payment service. The project is in C#, I am using Visual Studio 2010 and the SOAP version of the PayPal API. The version of the API I am using is 91.0 (tried switching this to other versions but the problem remains) and I am working in the sandbox to do the development.

在SOAP API开发人员指南中,我找到了WSDL,可以将服务导入到我的项目中作为Web参考.我可以执行Express Checkout付款流程的每个步骤.发出请求是在公园中散步,但使用服务的响应却不是.

In the SOAP API developer guide I found the WSDL to import the service in my project as web reference. I can do every step of the Express Checkout payment flow. Making requests is a walk in the park, using the responses from the service however are not.

由于某些原因,响应中的数据字段没有像我期望的那样自动填充.所有有用的字段均为空.因此,我必须手动解析响应中的XML字符串以获取所需的数据,而不仅仅是访问正确的对象.不用说,我不想这样工作.

For some reason the data fields in the response are not filled in automatically as I would expect. All useful fields are null. Because of this I manually have to parse the XML-string in the response to get the data I need instead of just accessing the right objects. Needless to say, I do not want to work this way.

付款流程最后一步(DoExpressCheckout)的简短示例:

A quick example from the last step of the payment flow (DoExpressCheckout):

PayPalAPIAASoapBinding apiaa = new PayPalAPIAASoapBinding();
apiaa.RequesterCredentials = ... ;

DoExpressCheckoutPaymentReq decreq = new DoExpressCheckoutPaymentReq();
decreq.DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType();
/* Filling in all the fields required */

DoExpressCheckoutPaymentResponseType decres = apiaa.DoExpressCheckoutPayment(decreq);

decres对象通常具有一个字段DoExpressCheckoutPaymentResponseDetails,其中包含我需要的所有详细信息.根据手册以及我的期望,例如,我应该能够读取响应中返回的令牌,如下所示:

The decres object normally has a field DoExpressCheckoutPaymentResponseDetails that contains all details I need. According to the manual and what I expect, I should be able to, for example, read the token returned in the reponse like this:

string token = decres.DoExpressCheckoutPaymentResponseDetails.Token;

相反,DoExpressCheckoutPaymentResponseDetails字段为null,我得到了这样的令牌:

Instead, the DoExpressCheckoutPaymentResponseDetails field is null and I have get the token like this:

string token = decres.Any.ChildNodes[0].InnerText;

我没有从PayPal服务获得任何错误代码.

I do not get any error codes from the PayPal service.

更奇怪的是,当我使用TransactionSearch函数查找多个事务时.说函数返回50个事务.阅读正确的对象后,将在正确的对象中填充49个事务.但是,第一个事务不是,必须从响应中的任何"字段手动解析.

Even more strange is when I use the TransactionSearch function to find multiple transactions. Say the functions returns 50 transactions. 49 transactions are filled in the correct object where one would expect to find them after reading the API documentation. The first transaction however is not and has to be parsed manually from the Any field in the response.

有人曾遇到同样或相似的问题吗?

Did anyone ever encoutered the same or similar problem?

Fyi:我习惯于对Web应用程序PHP进行编程.根据特定的需求,我在C#中执行此操作.这是标准的C#还是Visual Studio的行为(怀疑),还是我在Visual Studio中以错误的方式来做/配置SOAP服务的一个方面?

Fyi: I am used to programming web applications PHP. On specific demand I am doing this in C#. Is this standard C# or Visual Studio behaviour (doubt it) or am I doing/configuring an aspect of the SOAP service the wrong way in Visual Studio?

推荐答案

已解决:解决方案是停止使用旧版"Web参考",而改用较新的标准服务参考.

SOLVED: The solution is to STOP USING THE LEGACY "WEB REFERENCE", use the newer standard Service Reference instead.

我的大多数代码都可以在新的Service Reference上正常工作,我只需要设置Web.config并更改创建服务实例的方式即可.

Most of my code worked just fine with the new Service Reference, I just had to setup the Web.config and change the way I create an instance of the service.

返回新的PayPalAPIAAInterfaceClient("PayPalAPIAA"); 取代了PayPalAPIAASoapBinding.

return new PayPalAPIAAInterfaceClient("PayPalAPIAA"); took the place of PayPalAPIAASoapBinding.

原始帖子跟随.......

Original Post Follows.......

我第二个问题是,这不是凭证无效,交易失败或API版本不匹配的问题.我做得很好,响应中确实包含一个令牌,但是它进入了anyField变量,而不是它所属的位置.

I second this question, it's not a matter of invalid credentials, failed transaction, or mismatched API version. I'm doing everything right, the response DOES contain a Token, but it is going into the anyField variable rather than where it belongs.

当我从VS 2008 .Net 3.5升级到VS 2010 .Net 4之后,此错误使人头很丑.我怀疑该错误不是在PayPal方面,而是.Net 4 XML解析中的一个错误.

This bug reared it's ugly head after I upgraded from VS 2008 .Net 3.5 to VS 2010 .Net 4. I suspect that the bug is not on the PayPal side, but rather a bug in .Net 4 XML Parsing.

令牌应在此处进入令牌属性...

The Token should be going into the Token property here...

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:ebay:api:PayPalAPI")]
public partial class SetExpressCheckoutResponseType : AbstractResponseType {

    private string tokenField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Token {
        get {
            return this.tokenField;
        }
        set {
            this.tokenField = value;
        }
    }
}

相反,它到这里结束了....

Instead it ends up here....

[System.Xml.Serialization.XmlAnyElementAttribute()]
        public System.Xml.XmlElement Any {
            get {
                return this.anyField;
            }
            set {
                this.anyField = value;
            }
        }

我也许可以在Reference.cs文件中修复此问题,但是一旦更新Web服务参考,我的修复就会被覆盖.

I may be able to fix this inside the Reference.cs file, but my fix would be overwritten as soon as I update the web service reference.

这里还有其他人遇到相同的问题,但是他们的解决方案对我不起作用. https://www .x.com/developers/paypal/forums/soap/paypal-api-aa-and-net-wcf-undeserialized-fields

Here is someone else with the same problem, but their solution didn't work for me. https://www.x.com/developers/paypal/forums/soap/paypal-api-aa-and-net-wcf-undeserialized-fields

帮助!

这篇关于PayPal SOAP API响应需要手动解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆