视觉基础。方法无法体现
Visual Basic. Method cannot be reflected
我在 vb.net 和 Visual Studio 2015 社区中使用 soap 客户端时遇到问题。我想使用 soap 客户端库,但是找不到。
所以,我在 Visual Studio 2015 社区中找到了 wsdl.exe
命令。我试过了wsdl.exe。它生成了下面的代码 link:
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\
我添加了Project,编译成功。但是在实例化该行对象时出现异常
Dim LocationServiceWsdl As New LocationService()
下面是错误信息。
Message: LocationService.get cannot to be reflected
InnnerException: An error occurred while reflecting the SoapHeader.
at:
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)
System.Web.Services.Protocols.SoapClientType.GenerateXmlMappings(Type type, ArrayList soapMethodList, String serviceNamespace, Boolean serviceDefaultIsEncoded, ArrayList mappings)
System.Web.Services.Protocols.SoapClientType..ctor(Type type)
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
如何解决错误?
如果检查 innerexception,您会发现实际错误与 wsdl.exe 生成的 SoapHeader class 有关。
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 class 重命名为其他名称,或者将完整的命名空间添加到 XmlTypeAttribute 中的 class:
'''<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
我在 vb.net 和 Visual Studio 2015 社区中使用 soap 客户端时遇到问题。我想使用 soap 客户端库,但是找不到。
所以,我在 Visual Studio 2015 社区中找到了 wsdl.exe
命令。我试过了wsdl.exe。它生成了下面的代码 link:
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\
我添加了Project,编译成功。但是在实例化该行对象时出现异常
Dim LocationServiceWsdl As New LocationService()
下面是错误信息。
Message: LocationService.get cannot to be reflected
InnnerException: An error occurred while reflecting the SoapHeader.
at:
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)
System.Web.Services.Protocols.SoapClientType.GenerateXmlMappings(Type type, ArrayList soapMethodList, String serviceNamespace, Boolean serviceDefaultIsEncoded, ArrayList mappings)
System.Web.Services.Protocols.SoapClientType..ctor(Type type)
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
如何解决错误?
如果检查 innerexception,您会发现实际错误与 wsdl.exe 生成的 SoapHeader class 有关。
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 class 重命名为其他名称,或者将完整的命名空间添加到 XmlTypeAttribute 中的 class:
'''<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