You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助将SOAP POST请求转换为VB.NET代码并排查远程服务器无响应问题

Fixing Your VB.NET SOAP Request for Velocify ModifyLeadStatus

Let's walk through the issues in your code and get that SOAP request working properly:

Key Issues in Your Current Code

Here are the main problems causing the "cannot get response from remote server" error:

  • Incorrect Request URL
    You're sending the request to https://www.service.velocify.com, but the correct endpoint (per the supplier's spec) is https://service.velocify.com/ClientService.asmx — you missed the /ClientService.asmx path and added an extra www. which likely doesn't point to the right service.

  • Missing SOAPAction Header
    The SOAPAction header is required for this service, and you've commented out the line that sets it. The correct value matches what the supplier provided: "https://service.leads360.com/ModifyLeadStatus".

  • Mismatched SOAP Version
    Your code uses SOAP 1.2 (xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"), but the supplier's example uses SOAP 1.1 (xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"). This mismatch will cause the server to reject your request.

  • Wrong Data Type for statusId
    The supplier defines statusId as an integer, but your XML has <statusId>string</statusId> — this will cause a validation error on the server side.

  • Broken Response Handling
    You've commented out the code that retrieves the server response, and your StreamReader is trying to read from the already-closed request stream (not the response stream).

Corrected VB.NET Code

Here's the fixed version of your function with all these issues addressed:

Module Velocify
    ' Return a boolean to indicate success/failure
    Function SOAPRequest(username As String, password As String, leadId As Integer, statusId As Integer) As Boolean
        Dim request As WebRequest
        Dim response As WebResponse = Nothing
        Dim dataStream As Stream = Nothing
        Dim reader As StreamReader = Nothing
        Dim soapByte() As Byte
        Dim soapStr As String
        Dim isSuccess As Boolean = True

        ' Build the SOAP XML with correct SOAP 1.1 namespace and valid values
        soapStr = "<?xml version=""1.0"" encoding=""utf-8""?>" &
                  "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " &
                  "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" " &
                  "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &
                  "<soap:Body>" &
                  "<ModifyLeadStatus xmlns=""https://service.leads360.com"">" &
                  $"<username>{username}</username>" &
                  $"<password>{password}</password>" &
                  $"<leadId>{leadId}</leadId>" &
                  $"<statusId>{statusId}</statusId>" &
                  "</ModifyLeadStatus>" &
                  "</soap:Body>" &
                  "</soap:Envelope>"

        Try
            ' Convert SOAP string to bytes
            soapByte = System.Text.Encoding.UTF8.GetBytes(soapStr)
            
            ' Correct request URL
            request = WebRequest.Create("https://service.velocify.com/ClientService.asmx")
            
            ' Add required SOAPAction header
            request.Headers.Add("SOAPAction", "https://service.leads360.com/ModifyLeadStatus")
            
            ' Set correct content type and method
            request.ContentType = "text/xml; charset=utf-8"
            request.ContentLength = soapByte.Length
            request.Method = "POST"

            ' Write the SOAP data to the request stream
            dataStream = request.GetRequestStream()
            dataStream.Write(soapByte, 0, soapByte.Length)
            dataStream.Close()

            ' Get and read the server response
            response = request.GetResponse()
            dataStream = response.GetResponseStream()
            reader = New StreamReader(dataStream)
            Dim responseText As String = reader.ReadToEnd()
            
            ' Optional: Log or process the response text here
            Console.WriteLine("Server Response: " & responseText)

        Catch ex As WebException
            ' More detailed error handling (check response status if available)
            If ex.Response IsNot Nothing Then
                Using errorReader As New StreamReader(ex.Response.GetResponseStream())
                    MsgBox("Error Response: " & errorReader.ReadToEnd())
                End Using
            Else
                MsgBox("Request Error: " & ex.ToString())
            End If
            isSuccess = False
        Catch ex As Exception
            MsgBox("Unexpected Error: " & ex.ToString())
            isSuccess = False
        Finally
            ' Clean up resources to avoid leaks
            reader?.Close()
            dataStream?.Close()
            response?.Close()
        End Try

        Return isSuccess
    End Function
End Module

Additional Notes

  • I've updated the function to accept parameters for username, password, leadId, and statusId instead of hardcoding placeholder values — this makes it reusable.
  • Added proper resource cleanup in a Finally block to prevent memory leaks.
  • Enhanced error handling to read the server's error response (if available), which will help you debug any future issues with the request.
  • Used string interpolation ($"") for cleaner XML construction.

内容的提问来源于stack exchange,提问作者cowboycodering

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 21:02:50