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.
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 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

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

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

21 Experts available now in Live!

Get 1:1 Help Now