473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

soap request using vb .net

15
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.
Apr 14 '09 #1
17 56490
Frinavale
9,735 Expert Mod 8TB
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?
Apr 14 '09 #2
vlsw
15
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.
Apr 14 '09 #3
Frinavale
9,735 Expert Mod 8TB
Have you declared a variable that can be used as "proxy" to the web service?
Apr 14 '09 #4
vlsw
15
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"
Apr 14 '09 #5
Frinavale
9,735 Expert Mod 8TB
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
Apr 15 '09 #6
vlsw
15
Thank you. I will check it out.
Apr 15 '09 #7
vlsw
15
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
Apr 15 '09 #8
Frinavale
9,735 Expert Mod 8TB
Try using:
Expand|Select|Wrap|Line Numbers
  1.         txtboxResults.Text = node.InnerText()
Let me know how it goes :)

-Frinny
Apr 15 '09 #9
vlsw
15
Works thanks. I must repay you for your time. So here are 1 million smooches!
Apr 15 '09 #10
vlsw
15
One last thing. Still having issues displaying the response.
Apr 15 '09 #11
Frinavale
9,735 Expert Mod 8TB
What's wrong with it?
Apr 15 '09 #12
vlsw
15
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.
Apr 15 '09 #13
Frinavale
9,735 Expert Mod 8TB
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
Apr 15 '09 #14
vlsw
15
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.
Apr 15 '09 #15
Frinavale
9,735 Expert Mod 8TB
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)
Apr 15 '09 #16
iam_clint
1,208 Expert 1GB
doesn't soap just need a http request? I would use xmlhttp

http://robz.homedns.org:8080/blog/ar...02/25/387.aspx
Apr 16 '09 #17
vlsw
15
I'm sorry for not stating that the problem is handled. It was a glitch on their side everything is working fine now.
Apr 16 '09 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: The Grand Admiral | last post by:
Question. I have a wsdl soap request structure as follows: <soap:Envelope xmlns:xsi="..." xmlns:xsd="..." xmlns:soap="..."> <soap:Header>... </soap:Header> <soap:Body> <SaveItem xmlns="...">...
0
by: ramas | last post by:
Hi, I am new to PHP scripting and i am trying to connect to a soap server (as mentioned below) using the SOAP extension comesup with PHP. Now my requirement is to add my HTTP header fields along...
0
by: nitin via DotNetMonster.com | last post by:
Hi I had developed a VB.NET desktop client application which act as a SOAP client. To invoke the web service method I am using MSSOAP(2.0)'s low level interfaces. i.e SoapSerializer,SoapReader and...
0
by: Amar | last post by:
I am recieving the "The root element is missing" error from my soap extension while attempting to validate an incoming SOAP message request. I suspect the problem resides in the ChainStream method...
3
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce...
2
by: urs | last post by:
Hello, I want to intercept every request made to a web service in order to be able to display the actual SOAP request in a WebBrowser control (for documentation purposes in a test tool). I know how...
0
by: Florian Laws | last post by:
Hello, to work around an interoperability problem with the PHP5 SOAP extension, I'd like to modify the generate XML SOAP request. (as described in...
1
by: moorcroft | last post by:
I'm sending the following SOAP request to a webservice (I've had to star out some parts of it for privacy purposes): <?xml version="1.0" encoding="UTF-8"?> <soap-env:Envelope...
4
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
Why is it so difficult?!? Ok, Bungie has created an API for their new game, Halo Reach. The API allows you to access details stats and information about the game. There are two endpoints, JSON...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.