using wcf webservice results in a gridview in a vb app

Posted on 2015-01-23
Last Modified: 2015-01-26
I have a WCF web service built w/ C# working on localhost.  I can call it w/ a URI and get proper results back (it queries a remote SQL Server). However when trying to consume these results in a gridview in another project, I keep running into the [widely discussed] error about inability to locate endpoints.
The problem is almost certainly in the app.config (for the app) and the web.config (for the service) not properly synchronized or set. These files are attached, as is the code calling the service in the appIService1.csIService1.csService1.svc.cs Default.aspx.vbApp.config
Question by:Mark Klein
  • 7
  • 2
LVL 22

Assisted Solution

ambience earned 334 total points
ID: 40567933
I looks like you manually copied contents across config files. Have you tried adding a service reference using the IDE? Since the service exposes metadata, it should work.

Author Comment

by:Mark Klein
ID: 40568083
Yes, I tried that.  When it didn't work, started mucking with the ServiceModel code.

Been using Visual Studio Express 2013 For Web, which is partially limited in options,   So far no luck getting the Add Service Reference function to access the service unless I build the client app within the same solution. I pick a particular virtual directory for the service.

 I'm starting fresh this morning, first rebuilding the service and then adding a client app.  My only real option there for a new project within the solution is ASP.Net web application.  The walkthrough's I tried to follow usually call for a Windows form app.  I need my client app to run as a web site, so wondered if I should try to build a website rather than a project, outside the solution. Any advice on overall architecture appreciated.  --mark

Author Comment

by:Mark Klein
ID: 40568133
My web service gets data from a SQL Server db. Up to now, I've been using Linq, with which I have some familiarity.  My primary stuff will be coming from stored procedures. My first few services use Linq.

Will I be better off switching to ADO Entity Framework and getting up to speed there?
LVL 25

Assisted Solution

apeter earned 166 total points
ID: 40569245
since you are running in the same machine . Are you running wcf service project  prior to  grid view second project ?

Author Comment

by:Mark Klein
ID: 40569490
I'm still struggling, and would be pulling my hair if there were any left.
Now using VS Professional 2013 as my dev/IDE.  Service project and gridview project are in same solution.  The gridview project is marked as the startup project.  I'm assuming, dangerously, that the service project is started before it's called.
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 22

Accepted Solution

ambience earned 334 total points
ID: 40570233
Dangerous it is, the service should be running prior to adding the reference because the MEX endpoint will provide data that is used for creating the reference.

As for EF, it would definitely be a wise choice to embrace it. I wouldnt go into the benefits here since you can find a lot of articles that explain that much better. Lazy loading, change-tracking are some benefits worth considering.

Author Comment

by:Mark Klein
ID: 40570254
I'm learning to use svcutil in hopes that tool will help with the proxies.  I'm an 80+ years old geezer getting back into programming after literally 50 years, so it's a struggle.

How do I guarantee the service is started first?  Both the service and the consuming app are in the same solution.  I set the solution as the project start.  If I set the service as the project start, how do I get the client app going?

I did build the service using EF, still struggled, went back to Linq.  Eventually I'll go to EF, but I need to get this Hello World exercise going first.  I'm fairly sure the problem is in the servicemodel section of the configs for the two projects, and would really like a hand getting them right.

Author Comment

by:Mark Klein
ID: 40570296
Tried to test starting the service first.  Started service, then started to build a test client app in another solution so that I could start it when I knew the service was running. Got stopped when I tried to do Add Service Reference.  Put in the url of the running service at //localhost:15024/service1.svc, got error message
saying not able to find contract for IMetadataExchange, and that I need to add a ServiceMetadataBehaviors to the config, presumably the web.config of the service. Seems to me that I have that.  Here's a snippet:
        <behavior name="metadataBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        <behavior name="webBehaviour">
        <behavior name="webEndpoint">
            <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Xml" 

Open in new window

What more is needed?

Author Comment

by:Mark Klein
ID: 40570362
After some diddling, I am now able to do Add Service Reference from another solution and find the running service. Now struggling to use same to fill a gridview in a test app

Author Comment

by:Mark Klein
ID: 40570578
My running web service (in another project) has the namespace Arrows9WS

My service reference in my TestApp2 is ArrowsWebServiceReference.

I'm trying to fill a gridview upon a button click in TestApp2.TestForm2.  The event handler for the button click is where I'm struggling--see below code:
Dim client As Arrows9WS.Service1 = New Arrows9WS.Service1Client()

        'define the input parameters
        Dim CustomerId As String = "317318"
        'need input as string, but web service converts it to int for the stored proc
        'Dim CustomerIdNumber As Integer = Convert.ToInt32(CustomerId)
        Dim ProductCategory As String = "Play Things"

        'Invoke the public WebMethod that returns a DataSet.
        gvWebServiceData.DataSource = client.GetTopCrossSells(CustomerId, ProductCategory)

        'Bind the DataGrid to the returned DataSet.

Open in new window

I'm tripping up trying to declare 'cliient' now that my service reference recognizes the web service. I can't get Intellisense to make a sensible suggestion. Do I need an Import? Suggestions? C# or VB.  I'm doing the test app in VB b/c this is demo project, and I've got the web service running in C#.

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

28 Experts available now in Live!

Get 1:1 Help Now