Link to home
Start Free TrialLog in
Avatar of ravensFAC
ravensFAC

asked on

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

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!
ASKER CERTIFIED SOLUTION
Avatar of ChetOS82
ChetOS82
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of ravensFAC
ravensFAC

ASKER

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
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>
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.
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?
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?
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.
Hmm, no reference.vb file?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Expert was very helpful, but my solutions were cobbled together from several suggestions and personal research along with some luck.