【问题标题】:Visual Basic. Method cannot be reflected视觉基础。方法无法体现
【发布时间】:2016-10-03 12:06:12
【问题描述】:

我在 vb.net 中使用带有 Visual Studio 2015 社区的 soap 客户端时遇到问题。我想用soap客户端库,但是找不到。

所以,我在 Visual Studio 2015 社区中找到了wsdl.exe 命令。我试过wsdl.exe。它在以下链接中生成了代码:

https://github.com/yahoojp-marketing/sponsored-search-api-documents/blob/master/wsdl/LocationService.wsdl

C:\Program Files\Microsoft Visual Studio 14.0>wsdl /l:VB https://ss.yahooapis.jp/services/V6.0/LocationService?wsdl /out:C:\Users\user_name\Desktop\

我添加了项目并成功编译它。但是,实例化该行中的对象时会发生异常。

Dim LocationServiceWsdl As New LocationService()

以下是错误信息。

消息:LocationService.get 无法反映
InnnerException:反映 SoapHeader 时发生错误。
在:
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)
System.Web.Services.Protocols.SoapClientType.GenerateXmlMappings(类型类型、ArrayList soapMethodList、String serviceNamespace、Boolean serviceDefaultIsEncoded、ArrayList 映射)
System.Web.Services.Protocols.SoapClientType..ctor(类型类型)
System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()

LocationService.vb

<System.Web.Services.Protocols.SoapHeaderAttribute("RequestHeader"),
 System.Web.Services.Protocols.SoapHeaderAttribute("ResponseHeader", Direction:=System.Web.Services.Protocols.SoapHeaderDirection.Out),
 System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace:="http://ss.yahooapis.jp/V6", ResponseNamespace:="http://ss.yahooapis.jp/V6", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>
Public Function [get](ByVal accountId As Long, <System.Xml.Serialization.XmlElementAttribute("error")> ByRef [error]() As [Error]) As <System.Xml.Serialization.XmlElementAttribute("rval")> LocationReturnValue
    Dim results() As Object = Me.Invoke("get", New Object() {accountId}) ' <- maybe error occurs here.
    [error] = CType(results(1), [Error]())
    Return CType(results(0), LocationReturnValue)
End Function

我该如何解决这个错误?

【问题讨论】:

    标签: vb.net visual-studio windows-7 .net-4.5


    【解决方案1】:

    如果您检查内部异常,您可以看到实际错误与 wsdl.exe 生成的 SoapHeader 类有关。

    Types 'System.Web.Services.Protocols.SoapHeader' and 'FullNamespaceToYourClass.SoapHeader' both use the XML type name, 'SoapHeader', from namespace 'http://ss.yahooapis.jp/V6'. Use XML attributes to specify a unique XML name and/or namespace for the type.
    

    您可以将 LocationService.vb 文件中的 SoapHeader 类重命名为其他名称,或者将完整的命名空间添加到 XmlTypeAttribute 中的类:

    '''<remarks/>
    <System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0"),
    System.SerializableAttribute(),
    System.Diagnostics.DebuggerStepThroughAttribute(),
    System.ComponentModel.DesignerCategoryAttribute("code"),
        System.Xml.Serialization.XmlTypeAttribute(TypeName:="FullNamespaceToYourClass.SoapHeader", [Namespace]:="http://ss.yahooapis.jp/V6"),
    System.Xml.Serialization.XmlRootAttribute("RequestHeader", [Namespace]:="http://ss.yahooapis.jp/V6", IsNullable:=False)>
    
    Partial Public Class SoapHeader
        Inherits System.Web.Services.Protocols.SoapHeader
    

    【讨论】:

      猜你喜欢
      • 2013-04-02
      • 2014-08-21
      • 2012-12-22
      • 1970-01-01
      • 2015-06-09
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多