环境: 的Visual Studio 2010专业 .NET Framework 4的 下,用下面的WSDL#在C#中集成贝宝/使用WSDL NET解决方案(SOAP)
增值服务参考:https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl
问题1:当像这样编译时,从Reference.cs文件中得到一堆错误。看起来像命名空间错误。它提到它无法在我的项目的命名空间中找到服务引用命名空间。因此,我进入Reference.cs文件,无论我遇到这个错误,我在方法名称前删除了项目的名称空间,现在编译它。
终于可以访问所有的类。 创建和填充DoDirectPaymentReq和CustomSecurityHeader具有所需属性的对象。 创建了一个PayPalAPIAAInterfaceClient类的实例,该类包含方法DoDirectPayment,它接受CustomSecurityHeader和DoDirectPaymentReq类型的参数。看起来是这样的:
using (var client = new **PayPalAPIAAInterfaceClient**())
{
var credentials = new CustomSecurityHeaderType
{
Credentials = new UserIdPasswordType
{
Username = "[email protected]",
Password = "xxxxxxx",
Signature = "jksadfuhasfweakjhasf"
}
};
_doDirectPaymentResponseType = client.DoDirectPayment(ref credentials, _doDirectPaymentReq);
}
问题2:对包含上述代码的方法写一个TestMethod的后,我得到的错误如下:
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
因此,到目前为止,我还没有通过在C#中使用WSDL,能够使用PayPal SOAP协议进行成功的事务。
我当时觉得这很简单。只需添加服务引用,然后利用WSDL中代理中创建的属性和方法的类。
我哪里错了?
我使用错误的WSDL吗?我想先对Sandbox进行测试,然后进入Live。
如果我是正确的与WSDL,看起来像类PayPalAPIAAInterfaceClient不知道它的终点,我不知道如果我想以手动方式或不设置自已经在WSDL定义在那里结束(检查出来)。我认为类本身应该知道要调用哪个端点,具体取决于我是使用Signature还是Certificate来填充CustomSecurityHeaderType。
但PayPalAPIAAInterfaceClient类如何知道我是否试图调用沙盒(测试)还是实时事务?
PayPal用于Sandbox和Live两种不同的WSDL。他们可以在这里找到: - >https://cms.paypal.com/us/cgi-bin/?cmd=_render-content &的content_id =开发商/ e_howto_api_soap_PayPalSOAPAPIArchitecture
说在他们的支持后,我要求将以下WSDL用于Sandbox和Live: - >https://www.paypalobjects.com/wsdl/PayPalSvc。wsdl
但是,当它假设执行Live或Sandbox测试时,如何告诉PayPalAPIAAInterfaceClient类。并根据我的SOAP和签名方法使用哪个终点。来自PayPal的终点这里提到:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_endpoints
HELP!
OMG !!!我多愚蠢!为什么我没有看app.config!工作!谢谢你,谢谢你,谢谢你!虽然我从Paypal收回“版本不支持”错误。 – dparkar 2012-01-06 20:25:39
不支持的版本可以通过在SOAP请求中发送正确版本来解决:目前最新版本为84.0。 – Robert 2012-01-06 22:52:04
谢谢罗伯特!这也工作:) – dparkar 2012-01-09 16:26:38