我正在尝试通过SOAP方法与Web服务进行通信。代码适用于C#而不适用于VB。这很奇怪,我需要它与VB一起工作。有什么想法吗?
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace wsdltest
{
class Program
{
static void Main(string[] args)
{
hpsm.APSServer_Service apsServer = new hpsm.APSServer_Service();
int serviceReturn = 24081987;
var aTime = new hpsm.Timing();
aTime.id = "something";
aTime.endMillis = 100;
aTime.startMillis = 0;
aTime.subsystem = "aSubsystem";
aTime.threadID = "someThreadID";
var timing = new hpsm.Timing[] { aTime };
var message = "this is a message";
var payload = "payload";
var status = 24081987;
hpsm.service("testOp", "correlationID", "version", "environment", true, out serviceReturn, ref payload, out status, out message, out timing);
Console.WriteLine("service return = " +serviceReturn);
Console.WriteLine("message = " +message);
Console.WriteLine("status = " +status);
Console.WriteLine("timing = " + timing);
Console.WriteLine("payload = " + payload);
Console.ReadLine();
}
}
}
VB
Module Module1
Sub Main()
Dim hpsm As hpsm.APSServer_Service = New hpsm.APSServer_Service()
Dim serviceReturn As Integer = 24081987
Dim message As String = "this is a message"
Dim payload As String = "payload"
Dim status = 24081987
Dim aTime = New hpsm.Timing()
aTime.id = "something"
aTime.endMillis = 100
aTime.startMillis = 0
aTime.subsystem = "aSubsystem"
aTime.threadID = "someThreadID"
Dim timingArray() As hpsm.Timing = {aTime}
' call WebService
hpsm.service("testop", "correlationid", "version", "enviornment", True, serviceReturn, payload, status, message, timingArray)
End Sub
End Module
错误
(from Visual Studio 2017)
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=There was an error generating the XML document.
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage message)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at wsdlVB.hpsm.APSServer_Service.service(String operationName, String correlationID, String version, String environment, Boolean respTimeMonitoring, Int32& serviceReturn, String& payload, Int32& status, String& message, Timing[]& timings) in C:\Users\admhishaam\Documents\Visual Studio 2015\Projects\wsdlVB\wsdlVB\Web References\hpsm\Reference.vb:line 87
at wsdlVB.Module1.Main() in C:\Users\admhishaam\Documents\Visual Studio 2015\Projects\wsdlVB\wsdlVB\Module1.vb:line 24
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2147467262
Message=Specified cast is not valid.
Source=021yt0yo
StackTrace:
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAPSServer_Service.Write5_service(Object[] p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer5.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
InnerException:
从我传递给" hpsm.service"的参数中。方法,似乎在VB上它不满意参数' timing',并抱怨它无法序列化它。 '定时'是该方法的自定义类。这是方法
Public Sub service(ByVal operationName As String, ByVal correlationID As String, ByVal version As String, ByVal environment As String, ByVal respTimeMonitoring As Boolean, ByRef serviceReturn As Integer, ByRef payload As String, ByRef status As Integer, ByRef message As String, ByRef timings() As Timing)
Dim results() As Object = Me.Invoke("service", New Object() {operationName, correlationID, version, environment, respTimeMonitoring, payload})
serviceReturn = CType(results(0),Integer)
payload = CType(results(1),String)
status = CType(results(2),Integer)
message = CType(results(3),String)
timings = CType(results(4),Timing())
End Sub
这有点奇怪。