Solved

How to call and bind a web service to a control using VB.NET

Posted on 2011-03-01
14
660 Views
Last Modified: 2012-05-11
Hello,

I have several web services that I need to integrate into an existing site.  I have successfully tested all of them using a stand alone web service application so I know they are available and work.  I have also already added them as web references to my site using Visual Studio 2010.

Each service contains methods that return arrays, sometimes arrays within arrays, of data.  I need to be able to filter through all of these results and take actions based on them; sometimes displaying data, sometimes making behind the scenes actions.  I imagine that a repeater will give me the most flexibility with presentation, but to start off with I would just like to bind the raw results of some of the methods to a GridView just to know the connection is working and see the data on the screen.  I need guidance in binding the data to the control, but I'm getting errors even before I reach that point.  Here is what the VB.NET code looks like from within the Page_Load sub:

Dim wsRequest As New [Web Reference Name Here].[Web Service Name Here]
Dim wsResult As New wsResult
wsResult = wsResult .[Method Name Here]("Passed Value")

Open in new window


When refreshing the page I am getting the following error:
Compiler Error Message: BC30002: Type 'wsResult ' is not defined.

Open in new window


Any help consuming the Web Service and then binding to control is appreciated.

Thanks!
0
Comment
Question by:ravensFAC
  • 8
  • 6
14 Comments
 
LVL 18

Accepted Solution

by:
ChetOS82 earned 500 total points
ID: 35007500
You are creating wsRequest based on the Web Reference, but wsResult is based on some unknown class called "wsResult".  Is this a typo?  Where have you defined the wsResult class?
0
 

Assisted Solution

by:ravensFAC
ravensFAC earned 0 total points
ID: 35008613
Instead of wsResult I should have had the web reference name and response type.  that portion of code is working now.  I still have multiple issues.  The web service result contains a list of arrays which hold the data I need access to.  To start off with I just want to bind the wsResult to a control so I can see everything and be sure it is working.  What I tried was:

        wsResult = wsRequest.GetInfo("12345")
        myGridView.DataSource = wsResult
        myGridView.DataBind()

which yielded the error: Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource.

I am also frustrated because, although it isn't generating an error, the web reference does not seem to be recognized by VS and it is underlined in a blue squiggly and intellisense is not coming up.  I would think resolving this would help as well since this the result is more complex than a single method.  I don't understand why the web ref doesn't seem to be recognized when the reference seems to have been added correctly.  Did I miss a step?
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 35008902
You cannot bind an array to a gridview.  Can you run the site in a debugger and put a breakpoint there and see what is in the object?

As far as not recognizing the web reference, what object is being underlined?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:ravensFAC
ID: 35009045
Thanks for your help.  Unfortunately, I am not familiar with the built in debugger of VS.  I can see what is normally returned for that object via a stand alone web service testing tool I use.  If it helps I could paste the wsdl details on the complexType elements returned.

The objects underlined are:
Dim wsRequest As New [Web Reference Name Here].[Web Service Name Here]
Dim wsResult As New [Web Reference Name Here].wsDataAccessResult
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 35009068
Are you running this in Visual Studio?

If so, go the "myGridView.DataSource = wsResult" line and press F9, then run the application and when it gets to that line it will pause.  Hover over the word "wsResult" and you should be able to see the internals.
0
 

Assisted Solution

by:ravensFAC
ravensFAC earned 0 total points
ID: 35009528
I inherited this project.  Debugging showed 179 errors and then quit.  I don't think we can go down that path.  The web site runs fine, but I guess it was never run through a debugger.  I did make a little progress though.  I created a brand new web app and added my web reference to that and then added the same code to the default web page code behind.  the web reference is recognized and not underlined in blue.  Using intellisense and the wsdl I saw the object I needed to reference to bind to the GridView.

That solves the most basic of my questions about whether the service is working and returning data.  To go any further though I need to get intellisense working.  Do you have any idea why it isn't being recognized, although it does return data, in my existing project, but in the new project it also returns data but is recognized as well?  The only difference I saw is that in my existing project I have a App_WebReferences folder and in the new one the folder that was added automatically is simply 'Web References'.  Could it be some sort of configuration or permissions issue?
0
 

Author Comment

by:ravensFAC
ID: 35009622
The other difference I noticed was in the web.config.  The existing project refers to the web reference as:
<appSettings>
<add key="WebReferenceName.WebServiceName" value="http://IPAddress/ServiceName.asmx"/>
</appSettings>

while the new project refers to it as:

  <applicationSettings>
    <TestApp.My.MySettings>
      <setting name="TestApp_WebReferenceName_WebServiceName"
        serializeAs="String">
        <value>http://IPAddress/ServiceName.asmx</value>
      </setting>
    </TestApp.My.MySettings>
  </applicationSettings>
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 35010059
I don't know how you are adding a Web Reference if you aren't using Visual Studio.  When you add a web reference if creates (codegens) a class for you called WebServiceName, and then it gives you Intellisense based on that.  If you aren't getting Intellisense then it is because there is a problem with that codegen'ed file.  Since you cannot even compile your application, I think this is related.
0
 

Author Comment

by:ravensFAC
ID: 35011078
I am using Visual Studio 2010, but I don't see a class that was created.  Where is the class supposed to be located?  What I find odd, is that the web service works, but VS doesn't seem to know that it created the web reference for it.  I have tried deleting and recreating the web service.  Does the .NET version the site is running under make a difference?
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 35011108
The class should be under Web References.  It *might* be hidden in VS, look at the file system to see if it is there.  If not, it might be working because you project references a dll that has an old copy of the reference.

If you remove the reference does your code still work?
0
 

Author Comment

by:ravensFAC
ID: 35012192
The file system just has a folder the same name as the web reference that contains a .disco, .discomap, and .wsdl files.  The code does not work when I remove the web reference.
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 35012199
Hmm, no reference.vb file?
0
 

Assisted Solution

by:ravensFAC
ravensFAC earned 0 total points
ID: 35012323
Correct.  And to make everything even more confusing I just closed out the project and opened it up again and now the web service is being recognized by VS and intellisense is working.  This is good news for me, but during the day I have been making changes to the web.config, IIS, the web references and other changes so it is practically impossible to determine why it started working.  One of the more recent changes though was to removing and readding an assembly reference to system.web.extensions in the web.config file.  I also changed the app pool to 4.0, tried unsuccessfully to fix some errors that were caused by that move, and then moved the app pool back to 2.0.  Now all of the web references are being recognized.  I wish it was more clear to anyone who happens to come across this issue in the future and wants an answer, but I am really not positive which of the changes that were made fixed everything.

Also, for anyone looking for answers to another of my original questions, I was able to bind the web service results to a GridView by specifying only one of the multiple array types returned.  I know you said you can't bind an array to a GridView, but maybe this wasn't a true array even through it was labeled as such.  In any event, you were very helpful and I will award you full points for your effort.  I am going to close the question and post a more specific and less rambling one later tonight for the next step I need assistance with.

Thanks for your help.  
0
 

Author Closing Comment

by:ravensFAC
ID: 35045672
Expert was very helpful, but my solutions were cobbled together from several suggestions and personal research along with some luck.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question