Mono上运行eBay C#SDK时出现未经处理的异常

Mono上运行eBay C#SDK时出现未经处理的异常,c#,mono,ebay-sdk,C#,Mono,Ebay Sdk,我下载了eBay SDK,以便在我们正在开发的内部应用程序中使用。问题是我们正在开发Mono。在.NET上运行eBay Hello World示例时,它显示以下输出: +++++++++++++++++++++++++++++++++++++++ + Welcome to eBay SDK for .Net Sample + + - HelloWorld + +++++++++++++++++++++++++++++++++++++++ Begin

我下载了eBay SDK,以便在我们正在开发的内部应用程序中使用。问题是我们正在开发Mono。在.NET上运行eBay Hello World示例时,它显示以下输出:

+++++++++++++++++++++++++++++++++++++++
+ Welcome to eBay SDK for .Net Sample +
+ - HelloWorld                        +
+++++++++++++++++++++++++++++++++++++++
Begin to call eBay API, please wait ...
End to call eBay API, show call result:
eBay official Time: 11/27/2013 3:02:19 PM
当我使用Mono运行它时,我得到以下结果:

Unhandled Exception: eBay.Service.Core.Sdk.ApiException: Exception has been thrown by the target of an invocation. 
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: WebServiceBindingAttribute is required on proxy class 'eBay.Service.Core.Sdk.eBayAPIInterfaceService2'.
at System.Web.Services.Protocols.SoapTypeStubInfo..ctor (System.Web.Services.Protocols.LogicalTypeInfo logicalTypeInfo) [0x00000]
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&)
etc...etc...etc...

我找到了一个解决方法,并将其发布在下面的答案中。

我搜索了Xamarin的Bugzilla,但什么也没找到,但我在Novell的旧Mono Bugzilla中发现了这个相关的bug:

所以我翻遍了eBay SDK的源代码,发现这确实是个问题
eBay.Service.Core.Sdk.eBayAPIInterfaceService2
继承自
eBay.Service.Core.Sdk.eBayAPIInterfaceService
,该服务以
System.Web.Services.WebServiceBindingAttribute
装饰

因此,我更改了
eBay.Service.Core.Sdk.eBayAPIInterfaceService2
,添加了
[System.Web.Services.webserviceBerviceBindingAttribute(Name=“eBayAPISoapBinding”,Namespace=“urn:eBay:api:eBLBaseComponents”)
,使其看起来如下:

using System;
using System.Net;
using eBay.Service.Core.Soap;

namespace eBay.Service.Core.Sdk {
    /// <summary>
    /// Enhanced eBayAPIInterfaceService with GZIP compression support.
    /// </summary>
    [System.Web.Services.WebServiceBindingAttribute(Name = "eBayAPISoapBinding", Namespace = "urn:ebay:apis:eBLBaseComponents")]
    internal class eBayAPIInterfaceService2 : eBayAPIInterfaceService {
        ...
    }
}
使用系统;
Net系统;
使用eBay.Service.Core.Soap;
命名空间eBay.Service.Core.Sdk{
/// 
///增强的eBayAPIInterfaceService,支持GZIP压缩。
/// 
[System.Web.Services.WebServiceBindingAttribute(Name=“eBayAPISoapBinding”,Namespace=“urn:ebay:api:eblbbaseComponents”)]
内部类eBayAPIInterfaceService 2:eBayAPIInterfaceService{
...
}
}
我按照eBay SDK中的说明从源代码构建,问题得到了解决


脚注:顺便说一句,如果这是您第一次使用Mono连接到HTTPS web服务,您可能会立即遇到另一个异常。那一个看起来像这样:

Unhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0 
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0 
at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 
at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0 
未处理的异常:System.Net.WebException:获取响应流时出错(写入:身份验证或解密失败。):SendFailure-->System.IO.IOException:身份验证或解密失败。-->Mono.Security.Protocol.Tls.TlsException:从服务器接收到无效证书。错误代码:0xFFFF800B010A
位于:0中的Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates(Mono.Security.X509.X509CertificateCollection certificates)[0x00000]
位于:0中的Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1()[0x00000]
位于:0中的Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process()[0x00000]
at(带检查的包装器远程调用)Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process()
位于:0中的Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage(Mono.Security.Protocol.Tls.TlsStream handMsg)[0x00000]处
位于:0中的Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback(IAsyncResult asyncResult)[0x00000]处
---内部异常堆栈跟踪的结束---
在:0中的Mono.Security.Protocol.Tls.SslStreamBase.asynchHandshakeCallback(IAsyncResult asyncResult)[0x00000]处
---内部异常堆栈跟踪的结束---
0中的System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)[0x00000]处
位于:0中的System.Net.HttpWebRequest.GetResponse()[0x00000]

要解决这个问题,请点击这里:

mono的哪个版本?我使用的是3.2.3,但根据我在下面的答案中发布的Novell Bugzilla报告,这个bug至少在2.10.x版本就已经存在了。很可能这个bug是从0.1版本开始存在的;)请,总是你问一个关于mono的问题,指定你使用的版本道歉。。。本来打算,但兴奋得忘了贴答案。:)谢谢你的提醒!嘿,我在mono上遇到了一个类似的错误,有没有办法在不重新编译的情况下通过在.config文件中添加一些东西来解决这个问题?在这里向Xamarin报告了这个错误: