Reputation: 55
I have a problem using soap client in vb.net with Visual Studio 2015 Community. I want to use to soap client library, but I can't find it.
So, I found the wsdl.exe
command in Visual Studio 2015 Community. I tried wsdl.exe. It generated the code in the following 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\
I added the Project and successfully compiled it. However, an exception occurs when instantiate the object in this line.
Dim LocationServiceWsdl As New LocationService()
Below is the error message.
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()
<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
How can I resolve the error?
Upvotes: 0
Views: 680
Reputation: 1099
If you inspect the innerexception you can see the actual error is related to the SoapHeader class generated by wsdl.exe.
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.
You could either rename the SoapHeader class within the LocationService.vb file to something else or alternately add the full namespace to your class within the 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
Upvotes: 1