简体   繁体   English

Web服务行为随VB和C#改变

[英]Webservice behaviour changes with VB and C#

I am trying to communicate with a webservice over SOAP method. 我正在尝试通过SOAP方法与Web服务进行通信。 The code works with C# and not with VB. 该代码适用于C#,而不适用于VB。 Which is strange, I need it to work with VB. 奇怪的是,我需要它才能与VB一起使用。 Any ideas? 有任何想法吗?

C# 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 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

ERROR 错误

(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: 

From among the parameters I pass to the "hpsm.service" method, it seems that on VB it is not happy with the parameter 'timing', and complains that it is not able to serialize it. 在传递给“ hpsm.service”方法的参数中,似乎在VB上它对参数“ timing”不满意,并抱怨它无法序列化。 'timing' is a custom class of that method. “时间”是该方法的自定义类。 Here is the method 这是方法

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

Which is a bit strange. 这有点奇怪。

也许您可以尝试使用此转换器: http : //converter.telerik.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM