環境: 的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