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.
soap request using vb .net
Collapse
X
-
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.Comment
-
sample code
Code:Dim strEnvelope As String Dim request As New MSXML.XMLHTTPRequest Dim strReturn As String Dim objReturn As New MSXML.DOMDocument Dim strQuery As String Private Sub btnAcct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResidentAcct.Click strEnvelope = "POST /Account/Account.asmx HTTP/1.1 " & _ "Host: 1.1.1.1" & _ "Content-Type: text/xml; charset=utf-8" & _ "Content(655) : length()" & _ "SOAPAction: ""http://www.account.net/Account/Account""" & _ "<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:Body>" & _ "<Account xmlns=""http:// [url]www.account.net/Account[/url] "">" & _ "</Account>" & _ "</soap:Body>" & _ "</soap:Envelope>" 'Set up to post to our localhost server request.open("post", "http:// [url]www.account.net/Account[/url] ") request.setRequestHeader("Content-Type", "text/xml") request.setRequestHeader("Account", "http://www.account.net/Account/Account") request.send(strEnvelope) strReturn = request.responsetext objReturn.loadXML(strReturn) strQuery = "SOAP:Envelope/SOAP:Body/m:AccountResponse/Account"Last edited by Frinavale; Apr 15 '09, 01:44 PM. Reason: Added code tags. Please post code in [code] [/code] tags.Comment
-
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.
-FrinnyComment
-
Thanks that helped a lot. Although I do have a question. Here is my code so far
Now per the web service I am expecting a response likeCode:Private Sub btnAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccount.Click Dim node As Xml.XmlNode Dim strConnect As String Dim wsAccount As New Account() //proxy strConnect = wsAccount.TestWebServiceConnection() txtboxConnectStatus.Text = strConnect node = wsAccount.Account("0e7e6123-af7b-4e5e-a845-c6b0caf52 "", "", "1", "XML", "DOW", "JOHN", "9999") txtboxResults.Text = node.ToString() End Sub
But in my text box it returns System.Xml.XmlE lement.Code:HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?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:Body> <Response xmlns="http://www.account.net/Account"> <Result>xml</Result> </Response> </soap:Body> </soap:Envelope>
Any suggestionsComment
-
I am expecting the above response but I am not receiving it. I have called the webservice method via the proxyCode:HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?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:Body> <Response xmlns="http://www.account.net/Account"> <Result>xml</Result> </Response> </soap:Body> </soap:Envelope>
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.Code:xmlnode node = ws.Account() txtbox.text = node.innertext()
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.Comment
-
I haven't had to deal with SOAP directly since the first couple lectures I had on web services in college....afte r 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:
Code:Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. ' <System.Web.Script.Services.ScriptService()> _ <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _ <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ToolboxItem(False)> _ Public Class Service1 Inherits System.Web.Services.WebService <WebMethod()> _ Public Function HelloWorld() As String Return "Hello World" End Function <WebMethod()> _ Public Function Greeting(ByVal name As String) As String Return "Hello " + name + "!" End Function 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:
Please note that "localhost" is the namespace where my web service class (Service1) is located.Code:Private Sub showGreeting_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles showGreeting.Click Dim proxy As New localhost.Service1 'personsName is a TextBox greeting.Text = proxy.Greeting(personsName.Text) End Sub
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.
-FrinnyComment
-
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.Comment
Comment