在C#中集成贝宝/。NET解决方案使用WSDL(SOAP) [英] Integrating PayPal in C#/.NET Solution using WSDL (SOAP)

查看:540
本文介绍了在C#中集成贝宝/。NET解决方案使用WSDL(SOAP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:
的Visual Studio 2010专业版
.NET Framework 4的
C#



增值服务使用下面的WSDL参考: https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl



问题1 :在编译时干脆这样,弄一帮来自Reference.cs文件错误的。看起来命名空间的错误。它提到它不能在我的项目的命名空间找到服务引用命名空间。因此,我走进了Reference.cs文件,无论我得到这个错误,我的方法名称前被移除项目的命名空间,而现在它编译。<​​/ p>

终于等到访问所有类。
创建并填充了 DoDirectPaymentReq CustomSecurityHeader 所要求的属性的对象。
创建PayPalAPIAAInterfaceClient类的一个实例,其中包含该方法的 DoDirectPayment 这需要在类型CustomSecurityHeader和DoDirectPaymentReq的论点。看起来是这样的:使用(VAR的客户=新** ** PayPalAPIAAInterfaceClient())
{$ B $



  b VAR证书=新CustomSecurityHeaderType 
{
=证书新UserIdPasswordType
{
用户名=xxxxxxxx@xxxxxx.com,
密码=XXXXXXX,
签名=jksadfuhasfweakjhasf
}
};

_doDirectPaymentResponseType = client.DoDirectPayment(参考凭证,_doDirectPaymentReq);
}



问题2 :为写一个​​TestMethod的后其中包含上面的代码的方法,我得到的错误如下:

  System.InvalidOperationException:找不到默认端点元素引用在ServiceModel客户端配置部分合同Paypal.PayPalAPIAAInterface。这可能是因为没有配置文件,发现你的应用程序,或者是因为匹配这份合同没有终结点元素可以在客户端的元素被发现。 

在System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint,字符串configurationName)
在System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串configurationName,配置配置)
。在系统.ServiceModel.ChannelFactory.ApplyConfiguration(字符串configurationName)
在System.ServiceModel.ChannelFactory.InitializeEndpoint(字符串configurationName,地址的EndpointAddress)
在System.ServiceModel.ChannelFactory`1..ctor(字符串endpointConfigurationName,的EndpointAddress remoteAddress在System.ServiceModel.EndpointTrait`1.CreateSimplexFactory)
()在System.ServiceModel.ClientBase`1.CreateChannelFactoryRef
(EndpointTrait`1 endpointTrait)
在System.ServiceModel.ClientBase`1。 InitializeChannelFactoryRef()
在System.ServiceModel.ClientBase`1..ctor()
在PaymentEngine.Paypal.PayPalAPIAAInterfaceClient..ctor()在Reference.cs:行30063

因此,到目前为止,我还没有能够通过在C#中使用WSDL要使用贝宝SOAP协议交易成功。



我的印象是,这是非常简单的下面。简单地用它们的属性,并在从WSDL代理创建的方法添加服务引用和利用类。



我在哪里去了?



我使用了错误的WSDL?我想测试对沙盒,然后再进入现场。



如果我用WSDL是正确的,看起来像类的 PayPalAPIAAInterfaceClient不知道其端点,而如果我想以手动方式或不设置自已经在年底WSDL定义有我不知道(检查出来)。我认为类本身应该知道这取决于我是否使用签名或证书来填充CustomSecurityHeaderType调用哪个端点。



但如何PayPalAPIAAInterfaceClient类知道我是否想打电话到沙盒(测试)或者它是一个活的交易?



贝宝用于对沙箱和直播两种不同的WSDL。他们可以在这里找到:
- > https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_soap_PayPalSOAPAPIArchitecture



说在他们的支持后,我被要求使用下面的WSDL为沙盒和Live:
- > https://www.paypalobjects.com/ WSDL / PayPalSvc.wsdl



但我怎么告诉PayPalAPIAAInterfaceClient类时,它是假设执行Live或沙盒测试。同时也取决于我的SOAP和签名的方法使用到终点。来自PayPal端点这里提到:



https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_endpoints



HELP!


解决方案

您有几个问题在这里,但没有太痛苦来解决。首先,当我添加一个服务引用您在您的文章的顶部链接的WSDL,我没有任何与你描述的命名空间的问题。这可能是你自己的命名空间/引用的自动生成的条款在某种程度上相互冲突,或者您选择在添加引用过程中的一些奇怪的选项?一个删除和 - 重新添加可能会解决这个问题,或者我想你可以忽略它,因为你已经围绕它的工作。 (这是怎样的一个麻烦但是编辑自动生成的代码,所以你应该在修复计划最终的。)



要解决出现InvalidOperationException ,你可能只需要指定,Visual Studio已经自动添加到您的app.config文件中的一个端点。你应该有这样的事情在你的配置文件:

 < system.serviceModel> 
<客户端>
<端点名称=PayPalAPI... />
<端点名称=PayPalAPIAA... />
< /客户>
< /system.serviceModel>

您可以传给你想代理类的构造函数的端点的名称。有 以解决这个问题的其他选项,而只是指定的端点很容易和清洁。 (注:如果你没有这个部分在你的配置文件,然​​后在事情出错了的添加服务引用的阶段再次我只想建议重置您的项目,重新添加参考)



最后,你不想当你使用代理类的,尽管使用使用块它是的的IDisposable 。基本上,有一个在WCF 设计错误。


Environment : Visual Studio 2010 Professional .NET Framework 4 C#

Added Service Reference using the following WSDL : https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl

Problem 1 : When compiled simply like this, get a bunch of errors from the Reference.cs file. Looks like namespace errors. It mentions that it cannot find the Service Reference Namespace in my project's Namespace. Therefore, I went into the Reference.cs file and whereever I got this error, I removed the project's namespace before the method names, and now it compiles.

Finally getting access to all classes. Created and populated DoDirectPaymentReq and CustomSecurityHeader objects with the required properties. Created an instance of PayPalAPIAAInterfaceClient class, which contains the method DoDirectPayment which takes in the arguments of type CustomSecurityHeader and DoDirectPaymentReq. Looks like this :

using (var client = new **PayPalAPIAAInterfaceClient**())
{
   var credentials = new CustomSecurityHeaderType
   {
      Credentials = new UserIdPasswordType
      {
         Username = "xxxxxxxx@xxxxxx.com",
         Password = "xxxxxxx",
         Signature = "jksadfuhasfweakjhasf"
      }
   };

   _doDirectPaymentResponseType = client.DoDirectPayment(ref credentials, _doDirectPaymentReq);
}

Problem 2 : After writing a TestMethod for the method which contains the above code, I get the error as follows :

System.InvalidOperationException: Could not find default endpoint element that references contract 'Paypal.PayPalAPIAAInterface' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at System.ServiceModel.ClientBase`1..ctor()
at PaymentEngine.Paypal.PayPalAPIAAInterfaceClient..ctor() in Reference.cs: line 30063

Therefore, so far I have not been able to make a successful transaction using PayPal SOAP protocol via using WSDL in C#.

I was under the impression that this is very simple. Simply Add Service Reference and utilize the Classes with their properties and methods created in the proxy from WSDL.

Where am I going wrong ?

Am I using the wrong WSDL ? I'd like to test against Sandbox first and then go Live.

If I am right with the WSDL, looks like the class PayPalAPIAAInterfaceClient doesn't know its endpoint, which I don't know if I am suppose to set manually or not since its already there in the WSDL definition at the end (check it out). I think the class itself should know which endpoint to call depending on whether I am using Signature or Certificate to populate CustomSecurityHeaderType.

But how does the PayPalAPIAAInterfaceClient class know whether I am trying to call into the Sandbox (testing) or it is a live transaction ?

PayPal used to have two different WSDLs for Sandbox and for Live. They can be found here : ->https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_soap_PayPalSOAPAPIArchitecture

After speaking to their support I was asked to use the following WSDL for both Sandbox and Live: ->https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl

But how do I tell the PayPalAPIAAInterfaceClient class when it is suppose to perform Live or Sandbox tests. And also to which end point to use depending on my method of SOAP and Signature. The endpoints from PayPal are mentioned here :

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_endpoints

HELP !

解决方案

You have a few problems here, but none should be too painful to resolve. First of all, when I add a Service Reference to the WSDL you link at the top of your post I don't have any of the problems with namespaces that you describe. It could be that your own namespaces/references are conflicting somehow with the auto-generated terms, or perhaps that you selected some strange option during the add reference process? A delete-and-re-add might solve the problem, or I guess you can just ignore it since you've already worked around it. (It is kind of a hassle to edit auto-generated code, however, so you should plan on a fix eventually.)

To resolve the InvalidOperationException, you probably just need to specify one of the endpoints that Visual Studio has automatically added to your app.config file. You should have something like this in your config file:

<system.serviceModel>
  <client>
    <endpoint name="PayPalAPI" ... />
    <endpoint name="PayPalAPIAA" ... />
  </client>
</system.serviceModel>

You can pass the name of the endpoint you want to the constructor of the proxy class. There are other options to solve this problem, but just specifying an endpoint is easy and clean. (Note: if you don't have this section in your config file, then something went wrong during the Add Service Reference phase. Again I would just suggest resetting your project and re-adding the reference.)

Finally, you don't want to use a using block when you make use of the proxy class in spite of it being IDisposable. Basically, there's a design bug in WCF.

这篇关于在C#中集成贝宝/。NET解决方案使用WSDL(SOAP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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