静的参照をいじるのではなく、コード内で Web サービスを動的に呼び出してみませんか?
私は長い間このコードを使用してきましたが、どこで入手したか思い出せません:
Friend Class WsProxy
<SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted:=True)> _
Friend Shared Function CallWebService(ByVal webServiceAsmxUrl As String, ByVal serviceName As String, ByVal methodName As String, ByVal args As Object()) As Object
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf bypassAllCertificateStuff)
Dim client As New System.Net.WebClient()
' Connect To the web service
Dim stream As System.IO.Stream = client.OpenRead(webServiceAsmxUrl & "?wsdl")
' Now read the WSDL file describing a service.
Dim description As ServiceDescription = ServiceDescription.Read(stream)
'''// LOAD THE DOM /////////
' Initialize a service description importer.
Dim importer As New ServiceDescriptionImporter()
importer.ProtocolName = "Soap12"
' Use SOAP 1.2.
importer.AddServiceDescription(description, Nothing, Nothing)
' Generate a proxy client.
importer.Style = ServiceDescriptionImportStyle.Client
' Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties
' Initialize a Code-DOM tree into which we will import the service.
Dim nmspace As New CodeNamespace()
Dim unit1 As New CodeCompileUnit()
unit1.Namespaces.Add(nmspace)
' Import the service into the Code-DOM tree. This creates proxy code that uses the service.
Dim warning As ServiceDescriptionImportWarnings = importer.Import(nmspace, unit1)
If warning = 0 Then
' If zero then we are good to go
' Generate the proxy code
Dim provider1 As CodeDomProvider = CodeDomProvider.CreateProvider("CSharp")
' Compile the assembly proxy with the appropriate references
Dim assemblyReferences As String() = New String(4) {"System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll"}
Dim parms As New CompilerParameters(assemblyReferences)
Dim results As CompilerResults = provider1.CompileAssemblyFromDom(parms, unit1)
' Check For Errors
If results.Errors.Count > 0 Then
For Each oops As CompilerError In results.Errors
System.Diagnostics.Debug.WriteLine("========Compiler error============")
System.Diagnostics.Debug.WriteLine(oops.ErrorText)
Next
Throw New System.Exception("Compile Error Occured calling webservice. Check Debug ouput window.")
End If
' Finally, Invoke the web service method
Dim wsvcClass As Object = results.CompiledAssembly.CreateInstance(serviceName)
Dim mi As MethodInfo = wsvcClass.[GetType]().GetMethod(methodName)
Return mi.Invoke(wsvcClass, args)
Else
Return Nothing
End If
End Function
Private Shared Function bypassAllCertificateStuff(ByVal sender As Object, ByVal cert As X509Certificate, ByVal chain As X509Chain, ByVal [error] As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
End Class
これを使用するには、次のようなパラメーターを使用して Object 型の配列を作成するだけです。
Dim vParams(1) As Object
vParams(0) = "Some param" ' Some string parameter
vParams(1) = 12345 ' Some integer parameter
次に、クラスへの静的呼び出しを使用して呼び出します。
WsProxy.CallWebService("http://yourserviceurlhere/", "WsNamespace", "MethodName", vParams)
これにより、Web サービスの応答が何であれ、タイプ Object の応答が生成されます。それが役に立てば幸い。