Connecting Tech Pros Worldwide Forums | Help | Site Map

soap request using vb .net

Newbie
 
Join Date: Apr 2009
Posts: 14
#1: Apr 14 '09
I am new to soap and web services. I want to send an xml soap request to an existing web service created by outside party. how do i go about doing this and viewing the response. any help would be greatly appreciated.

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#2: Apr 14 '09

re: soap request using vb .net


Nice question.

I would have though it would be easy to look up an article on how to consume and use web services but apparently this has changed drastically and can't find a good enough article for you at this time.

What have you done so far?
Newbie
 
Join Date: Apr 2009
Posts: 14
#3: Apr 14 '09

re: soap request using vb .net


I have been looking all day for something that will do exactly what I need it to do. My search has been unsuccessful either b/c there is no info out there or I am extremely frustrated. Either way.

I have the soap xml created already. I am just having a problem sending it. I have just a simple form with two buttons and a list box. Each button calls a different method on a service (I didn't create service by the way I just want to access two methods) and I want the response to show up in a list box.

i guess my issue is after i create the message how do i send it.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#4: Apr 14 '09

re: soap request using vb .net


Have you declared a variable that can be used as "proxy" to the web service?
Newbie
 
Join Date: Apr 2009
Posts: 14
#5: Apr 14 '09

re: soap request using vb .net


sample code

Expand|Select|Wrap|Line Numbers
  1. Dim strEnvelope As String
  2.     Dim request As New MSXML.XMLHTTPRequest
  3.     Dim strReturn As String
  4.     Dim objReturn As New MSXML.DOMDocument
  5.     Dim strQuery As String
  6.  
  7.  
  8.  
  9.     Private Sub btnAcct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResidentAcct.Click
  10.  
  11.         strEnvelope = "POST /Account/Account.asmx HTTP/1.1 " & _
  12.         "Host: 1.1.1.1" & _
  13.         "Content-Type: text/xml; charset=utf-8" & _
  14.         "Content(655) : length()" & _
  15.         "SOAPAction: ""http://www.account.net/Account/Account""" & _
  16.               "<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/"">" & _
  17.           " <soap:Body>" & _
  18.             "<Account xmlns=""http:// www.account.net/Account "">" & _
  19.  
  20.               "</Account>" & _
  21.            "</soap:Body>" & _
  22.          "</soap:Envelope>"
  23.  
  24.  
  25.         'Set up to post to our localhost server
  26.         request.open("post", "http:// www.account.net/Account ")
  27.         request.setRequestHeader("Content-Type", "text/xml")
  28.         request.setRequestHeader("Account", "http://www.account.net/Account/Account")
  29.         request.send(strEnvelope)
  30. strReturn = request.responsetext
  31.   objReturn.loadXML(strReturn)
  32.  
  33.         strQuery = "SOAP:Envelope/SOAP:Body/m:AccountResponse/Account"
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#6: Apr 15 '09

re: soap request using vb .net


Ok I'm going to recommend you change your implementation to use a proxy class instead of trying to create the soap message by hand.

I've found an article that explains how to do this...sort of. It explains how to consume a web service in an asp.net application, but the same concepts should apply to a windows desktop application as well.

Check out this quick article and let me know if you're having any problems with it.

-Frinny
Newbie
 
Join Date: Apr 2009
Posts: 14
#7: Apr 15 '09

re: soap request using vb .net


Thank you. I will check it out.
Newbie
 
Join Date: Apr 2009
Posts: 14
#8: Apr 15 '09

re: soap request using vb .net


Thanks that helped a lot. Although I do have a question. Here is my code so far
Expand|Select|Wrap|Line Numbers
  1.   Private Sub btnAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccount.Click
  2.         Dim node As Xml.XmlNode
  3.         Dim strConnect As String
  4.         Dim wsAccount As New Account()  //proxy
  5.         strConnect = wsAccount.TestWebServiceConnection()
  6.         txtboxConnectStatus.Text = strConnect
  7.         node = wsAccount.Account("0e7e6123-af7b-4e5e-a845-c6b0caf52
  8.                      "", "", "1", "XML", "DOW", "JOHN", "9999")
  9.         txtboxResults.Text = node.ToString()
  10.     End Sub
Now per the web service I am expecting a response like

Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2. Content-Type: text/xml; charset=utf-8
  3. Content-Length: length
  4.  
  5. <?xml version="1.0" encoding="utf-8"?>
  6. <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/">
  7.   <soap:Body>
  8.     <Response xmlns="http://www.account.net/Account">
  9.       <Result>xml</Result>
  10.     </Response>
  11.   </soap:Body>
  12. </soap:Envelope>
But in my text box it returns System.Xml.XmlElement.

Any suggestions
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#9: Apr 15 '09

re: soap request using vb .net


Try using:
Expand|Select|Wrap|Line Numbers
  1.         txtboxResults.Text = node.InnerText()
Let me know how it goes :)

-Frinny
Newbie
 
Join Date: Apr 2009
Posts: 14
#10: Apr 15 '09

re: soap request using vb .net


Works thanks. I must repay you for your time. So here are 1 million smooches!
Newbie
 
Join Date: Apr 2009
Posts: 14
#11: Apr 15 '09

re: soap request using vb .net


One last thing. Still having issues displaying the response.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#12: Apr 15 '09

re: soap request using vb .net


What's wrong with it?
Newbie
 
Join Date: Apr 2009
Posts: 14
#13: Apr 15 '09

re: soap request using vb .net


Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK 
  2. Content-Type: text/xml; charset=utf-8 
  3. Content-Length: length 
  4.  
  5. <?xml version="1.0" encoding="utf-8"?> 
  6. <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/"> 
  7.   <soap:Body> 
  8.     <Response xmlns="http://www.account.net/Account"> 
  9.       <Result>xml</Result> 
  10.     </Response> 
  11.   </soap:Body> 
  12. </soap:Envelope> 
  13.  
I am expecting the above response but I am not receiving it. I have called the webservice method via the proxy
Expand|Select|Wrap|Line Numbers
  1. xmlnode node = ws.Account()
  2. txtbox.text = node.innertext()
i am only seeing what i sent accross but I am not getting a replay status or anything. the response is part of the wsdl but i am not able to access it.

however i did have to email about fields that were not required but the xml is returning a statement that the field information is missing.

but I still should receive something stating that the transmission was a success or failure and I see nothing.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#14: Apr 15 '09

re: soap request using vb .net


I haven't had to deal with SOAP directly since the first couple lectures I had on web services in college....after we understood what SOAP was (what made it valid, what it was used for, how to create it) and what WSDLs were all about we stopped looking at it.

Instead of working with SOAP and WSDLs manually, we depended on the tools that Java provided for creating and consuming web services. We let these tools deal with SOAP and WSDLs (understand that I was studying Java). In your case you should let .NET deal with the SOAP and WSDLs. You shouldn't be concerned with it (unless it has to do with security SOAP communications).

When you add a web reference to a web service in your application Visual Studio retrieves the WSDL. From this Visual Studio will dynamically create a class that can be used as a proxy to execute the methods provided by the web service.

This proxy class takes all of the SOAP and WSDL torture out of the experience of consuming web services. You use this class as you would any other .NET class and you should be able to execute the web methods without any problems. If there is a problem it's likely that an exception will be raised (which you can trap and deal with).

I don't know what you're trying to do with your Test Connection stuff.

Just to come up to speed with you I created a Web Service of my own and consume it in a button click.

The web service provides 2 methods: HelloWorld() and Greeting(string).
This is the web service code:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Web.Services
  2. Imports System.Web.Services.Protocols
  3. Imports System.ComponentModel
  4.  
  5. ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  6. ' <System.Web.Script.Services.ScriptService()> _
  7. <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
  8. <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  9. <ToolboxItem(False)> _
  10. Public Class Service1
  11.     Inherits System.Web.Services.WebService
  12.  
  13.     <WebMethod()> _
  14.     Public Function HelloWorld() As String
  15.        Return "Hello World"
  16.     End Function
  17.  
  18.     <WebMethod()> _
  19.     Public Function Greeting(ByVal name As String) As String
  20.         Return "Hello " + name + "!"
  21.     End Function
  22.  
  23. End Class

As you can see the Greeting function takes 1 parameter: a string containing a name. It returns a String with the greeting.

I added a reference to my project and in a button click event I consume the web service:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub showGreeting_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles showGreeting.Click
  2.         Dim proxy As New localhost.Service1
  3.  
  4.         'personsName is a TextBox
  5.         greeting.Text = proxy.Greeting(personsName.Text)
  6.     End Sub
Please note that "localhost" is the namespace where my web service class (Service1) is located.

I tried to figure out how to access the SOAP directly but could not find a way to do it....and I don't why you would want to.

-Frinny
Newbie
 
Join Date: Apr 2009
Posts: 14
#15: Apr 15 '09

re: soap request using vb .net


I understand and I don't want to access it directly. I thought that when the service was called the invoke method should return a response as well and part of that response is a status. I'm not getting that and it could be b/c there is a discrepency on which fields are required and which are not. Thanks again. I am able to get the web service connection so I wait until I hear back from them and go from there.


Thanks again.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,120
#16: Apr 15 '09

re: soap request using vb .net


I'm just glad that I was able to help you :)
It's been a long time since I've used Web Services and haven't seriously done anything with them since college. I would recommend researching web services using the MSDN Library while you're waiting for a response.

There is a lot of stuff to consider when using them (particularly with securing SOAP communications between the server and client...because, as you know, they are plain text)
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#17: Apr 16 '09

re: soap request using vb .net


doesn't soap just need a http request? I would use xmlhttp

http://robz.homedns.org:8080/blog/ar...02/25/387.aspx
Newbie
 
Join Date: Apr 2009
Posts: 14
#18: Apr 16 '09

re: soap request using vb .net


I'm sorry for not stating that the problem is handled. It was a glitch on their side everything is working fine now.
Reply