简体   繁体   English

如何使用vb.net使SOAP响应并使选定的元素进入文本框/数据集

[英]how to make SOAP RESPONSE and get selected element into textbox/dataset using vb.net

How to make SOAP REQUEST xml(asmx) response selected element into textbox or dataset. 如何使SOAP REQUEST xml(asmx)响应将所选元素放入文本框或数据集中。 here's my simple script: 这是我的简单脚本:

Protected Sub SOAPRequest(ByVal tarikh As String, ByVal jabatan As String, ByVal HRMS_asmx As String, ByVal tempuri As String)
    Dim xmlQuery As String = "<?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:Header>
                        <wsse:Security soap:mustUnderstand='true' 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'>
                        <wsse:UsernameToken wsu:Id='UsernameToken-3DAJDJSKJDHFJASDKJFKJ234JL2K3H2K3J42'>
                        <wsse:Username>660618055198</wsse:Username>
                        <wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>fouziah@123</wsse:Password>
                        <wsse:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'>3WSOKcKKm0jdi3943ts1AQ==</wsse:Nonce>
                        <wsu:Created>2015-01-12T16:46:58.386Z</wsu:Created>
                        </wsse:UsernameToken>
                        </wsse:Security>
                        </soap:Header>
                        <soap:Body>
                        <GetDataXMLbyDate xmlns='http://tempuri.org/'>
                              <tarikh>" + tarikh + "</tarikh>
                              <datatypes>
                                <NamaAgensi>" + jabatan + "</NamaAgensi>
                              </datatypes>
                            </GetDataXMLbyDate>
                          </soap:Body>
                        </soap:Envelope>"

    Dim doc As New XmlDocument()
    doc.LoadXml(xmlQuery)

    Dim req As HttpWebRequest = CType(WebRequest.Create(HRMS_asmx), HttpWebRequest)
    req.Headers.Add("SOAPAction", tempuri)
    req.Headers.Add("GetDataXMLbyDateResponse", "http://temuri.org")
    req.ContentType = "text/xml;charset=""utf-8"""
    req.Accept = "text/xml"
    req.Method = "POST"

    Dim stm As Stream = req.GetRequestStream()
    doc.Save(stm)
    stm.Close()

    Dim resp As WebResponse = req.GetResponse()
    stm = resp.GetResponseStream()
    Dim r As StreamReader = New StreamReader(stm)
    Response.Write(r.ReadToEnd())
End Sub

enter image description here enter image description here 在此处 输入图像描述在 此处 输入图像描述

and the second question is, using web reference 第二个问题是,使用网络参考

enter image description here 在此处输入图片说明

According to your screenshot, the code you posted has nothing at all to do with your error. 根据您的屏幕截图,您发布的代码与您的错误完全无关。 The method you are trying to call ( GetDataXMLByDate ) on the service reference takes two parameters but you are not providing any. 您尝试在服务引用上调用的方法( GetDataXMLByDate )具有两个参数,但您未提供任何参数。

I can't possibly give you exact code because I lack context but you need a string and you need an array of NamaAgensi . 我可能无法提供确切的代码,因为我缺少上下文,但是您需要一个字符串,并且需要一个NamaAgensi数组。 So look at this compared to what you are doing in that pageLoad method. 因此,与在该pageLoad方法中执行的操作相比,请看一下。

Dim arr as NamaAgensi() = New NamaAgensi(0) { someInstanceOfNamaAgensi}
service.GetDataXMLByDate(tarikh, arr)

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

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