3

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);
Erin
  • 41
  • 1
  • 2
  • 6
  • Please don't prefix your titles with "Web Service Client Using ASP.NET 4.0 VS Web Dev 2010 Express VB: " and such. That's what the tags are for. – John Saunders Feb 09 '12 at 20:41
  • Ok, I will make sure not to do that in the future! – Erin Feb 09 '12 at 22:06
  • No, please don't do that. You don't need to. You should just use WCF. See [How to Consume a Web Service](http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/) – John Saunders Feb 09 '12 at 22:33
  • Can WCF take the data from the XML document and pass it as a string to the web service and then receive the response as a string from the web service? If so, could you point me to a good example or tutorial. I'm really lost! – Erin Feb 10 '12 at 19:25
  • Look at http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/, then just pass the XML as a `string`. – John Saunders Feb 10 '12 at 20:25
  • Do you have any examples on how to pass the XML as a string? – Erin Feb 24 '12 at 21:53
  • I can't imagine why you need an example. Did you read the blog post and try consuming the service? If the service wants the XML as a string, all you would have to do is call it and pass the XML. – John Saunders Feb 24 '12 at 22:09
  • I think what I'm having a problem with is getting the data from an XML file into variables to pass. Is there a way to read the entire XML file into one big string and pass it? Or do I have to do it by pulling the xml values into variables and then calling the webservice with those variables? – Erin Feb 27 '12 at 14:37

1 Answers1

0

First of all, I strongly recommend against using a web site "project". That's only good for simple sites. If you're using web services, then I don't call your site "simple".

Second, you should not be using ASMX services at all. That's a legacy technology that shouldn't be used for new development. You should be using WCF for all new development.

I have left a comment on http://asp.net, asking them to please take that old video down. It's sent you on the wrong path.

John Saunders
  • 160,644
  • 26
  • 247
  • 397