Solved

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

Posted on 2011-03-01
14
649 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ravensFAC
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:ChetOS82
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hmm, no reference.vb file?
0
 

Assisted Solution

by:ravensFAC
ravensFAC earned 0 total points
Comment Utility
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
Comment Utility
Expert was very helpful, but my solutions were cobbled together from several suggestions and personal research along with some luck.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now