我在使用Visual Studio 2015社区的vb.net中使用soap客户端时遇到问题。我想用肥皂客户端库,但我找不到它。
因此,我在Visual Studio 2015社区中找到了wsdl.exe
命令。我试过wsdl.exe。它在以下链接中生成了代码:
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()
以下是错误消息。
消息:无法反映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(Type type,ArrayList soapMethodList,String serviceNamespace,Boolean serviceDefaultIsEncoded,ArrayList mappings)
System.Web.Services.Protocols.SoapClientType..ctor(Type type)
System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
<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
如何解决错误?
答案 0 :(得分:1)
如果检查了innerexception,您会发现实际错误与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