我正在尝试在vb.net中调用Web服务,并且我遵循了以下线程:WebService Send SOAP request and received response using visual Basic
这些是我遵循的步骤:
我已经手动将肥皂请求写入xml文件(I attach the xml file as image here )
我已将xml文件加载到字符串变量中,并像这样调用Web服务:
Dim strDocumentoSoap As String
Dim document As XDocument = XDocument.Load("C:\myFile.xml")
strDocumentoSoap = document.ToString
Dim servicioWeb As svc.v79jIntegracionPerfilSesion = New svc.v79jIntegracionPerfilSesion
Dim sbLogin As New System.Text.StringBuilder
sbLogin.Append(strDocumentoSoap)
Dim hwrequest As System.Net.HttpWebRequest
hwrequest = System.Net.WebRequest.Create("http://myServiceURL/realizarPeticionPublicacionOSBUS?WSDL")
hwrequest.Method = "POST"
hwrequest.ContentType = "text/xml; charset=utf-8"
Dim byteData As Byte() = System.Text.Encoding.UTF8.GetBytes(sbLogin.ToString())
hwrequest.ContentLength = byteData.Length
Dim writer As Stream = hwrequest.GetRequestStream
writer.Write(byteData, 0, byteData.Length)
writer.Close()
Dim Response As System.Net.HttpWebResponse
Response = hwrequest.GetResponse
Dim responseStatus As String = Response.StatusDescription.ToString
Dim DataStream As Stream
Dim Reader As StreamReader
DataStream = Response.GetResponseStream()
Reader = New StreamReader(DataStream)
Dim SD2Request As String = Reader.ReadToEnd()
'SHOW THE RESPONSE INTO MSGBOX
MsgBox(SD2Request)
这很好用,但是我在Internet上读到,不推荐这种做法(为SOAP手工制作XML),因为.net中还有其他有用的工具。
谁能向我解释在不手动创建soapenvelope的情况下在VB.NET中创建肥皂请求的其他选项或库。
非常感谢您!
玛加