VB.net SOAP Web服务小程序

时间:2018-11-28 15:34:59

标签: vb.net web-services soap

嗨,我正在尝试编写一个小的VB.net程序,该程序将更新我们oracle CPQ站点上的一些数据。基本上,我已经使用了从CPQ网站内部使用的示例XML作为测试(可直接在该网站上使用),并将其移植到vb.net程序中。我在第56行不断收到错误500“内部服务器错误” Response = Request.GetResponse()

    Dim Request As WebRequest
    Dim Response As WebResponse
    Dim DataStream As Stream
    Dim Reader As StreamReader
    Dim SoapByte() As Byte
    Dim SoapStr As String
    Dim pSuccess As Boolean = True


    SoapStr = "<?xml version=""1.0"" encoding=""utf-8""?>"
    SoapStr = SoapStr & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">"
    SoapStr = SoapStr & "<soapenv:Header/>"
    SoapStr = SoapStr & "<wsse:Security xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">"
    SoapStr = SoapStr & "<wsse:UsernameToken wsu:Id=""UsernameToken-2"">"
    SoapStr = SoapStr & "<wsse:Username>username</wsse:Username>"
    SoapStr = SoapStr & "<wsse:Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"">password</wsse:Password>"
    SoapStr = SoapStr & "</wsse:UsernameToken>"
    SoapStr = SoapStr & "</wsse:Security>"
    SoapStr = SoapStr & "</soapenv:Header>"
    SoapStr = SoapStr & "<soapenv:Body>"
    SoapStr = SoapStr & "<bm:modifyParts xmlns:bm=""http://xmlns.oracle.com/cpqcloud/parts"">"
    SoapStr = SoapStr & "<bm:Parts>"
    SoapStr = SoapStr & "<bm:each_record>"
    SoapStr = SoapStr & "<bm:part_number>0000158-01-LIMT-MX-10</bm:part_number>"
    SoapStr = SoapStr & "<bm:description>"
    SoapStr = SoapStr & "<bm:en>OPER - SOAP Test 1</bm:en>"
    SoapStr = SoapStr & "</bm:description>"
    SoapStr = SoapStr & "</bm:each_record>"
    SoapStr = SoapStr & "</bm:Parts>"
    SoapStr = SoapStr & "</bm:modifyParts>"
    SoapStr = SoapStr & "</soapenv:Body>"
    SoapStr = SoapStr & "</soapenv:Envelope>"

    Try
        SoapByte = System.Text.Encoding.UTF8.GetBytes(SoapStr)

        Request = WebRequest.Create("https://velaninctest.bigmachines.com/v2_0/receiver/parts")
        Request.Headers.Add("SOAPAction", "https://velaninctest.bigmachines.com/v2_0/receiver/parts")

        Request.ContentType = "text/xml; charset=utf-8"
        Request.ContentLength = SoapByte.Length
        Request.Method = "POST"

        DataStream = Request.GetRequestStream()
        DataStream.Write(SoapByte, 0, SoapByte.Length)
        DataStream.Close()

        Response = Request.GetResponse()
        DataStream = Response.GetResponseStream()
        Reader = New StreamReader(DataStream)
        Dim SD2Request As String = Reader.ReadToEnd()

        TextBox1.Text = SD2Request

        DataStream.Close()
        Reader.Close()
        Response.Close()

    Catch ex As WebException
        MsgBox(ex.ToString())
    End Try

不知道我在做什么错。您可以检查可用服务调用的WSDL定义:https://velaninctest.bigmachines.com/v2_0/receiver/

Sample from CPQ site to test SOAP call

1 个答案:

答案 0 :(得分:0)

您现在可能已经找到了它,但是看起来您在第12行的内容之前关闭了“”标签。无法与VB.net通话(时间太长),但CPQ Web服务调用看起来不错。

-克里斯