I am new to Web Services. I have created a new website in Visual Web Developer 2010 Express and added a Service Reference to a site's .asmx page and have given it a namespace of BBImportLead.
The end result would be to load several customers into one XML file from our PICK/Universe database, take the InnerText String for each tag (FName, LName, etc) from the xml file via ASP.NET, send the strings via SOAP to the web service, and display the result to the user (for now in a label, but future, possibly having actions taken depending on the result such as deleting the xml file if it's been sent successfully).
I have tried following different examples using VB and C#, but I'm not getting it to work. It looks like I was able to get very close following this example with VB: http://www.asp.net/web-forms/videos/building-35-applications/an-introduction-to-soap-based-web-services-with-visual-web-developer-2008
This is my Default.aspx.vb code behind. My goal is to display the string response from the web service in the Label I created.
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim BBImportLeadService As New BBImportLead.BBCallDataSoapClient
Dim doc As New System.Xml.XmlDocument
doc.Load("bborder.xml")
Dim AuthenHead = doc.GetElementsByTagName("AuthenHead")
Dim FName = doc.GetElementsByTagName("FName").ToString
Dim LName = doc.GetElementsByTagName("LName").ToString
Label1.Text = BBImportLeadService.ImportLead(AuthenHead:=AuthenHead, FName:=FName, LName:=LName)
End Sub
End Class
The error I am getting is in regards to the AuthenHead variable since it's not a string. It is a tns value, but I'm not sure how to use doc.GetElementsByTagName and convert it to what the service is asking for?
Error 1 Value of type 'System.Xml.XmlNodeList' cannot be converted to 'BBImportLead.AuthenHead'
Can anyone point me in the right direction? How to fix that tns error and if this looks like it should even work?
UPDATE: I have found this new piece of code for my C# attempt. Would this work better? It seems to send something and get a response, but I don't have the username and password for the web service to be getting their response. And I'm also not seeing where to call a specific function on their webservice for my xml data to go into.
string data = "bborder.xml";
string url = "urltakenoutforexample";
string servresponse = "the response from the server";
// build request objects to pass the data/xml to the server
byte[] buffer = Encoding.ASCII.GetBytes(data);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/soap+xml";
request.ContentLength = buffer.Length;
Stream post = request.GetRequestStream();
// post data and close connection
post.Write(buffer, 0, buffer.Length);
post.Close();
// build response object
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responsedata = response.GetResponseStream();
StreamReader responsereader = new StreamReader(responsedata);
servresponse = responsereader.ReadToEnd();
lbNodes.Items.Add(servresponse);