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?
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
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…
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…

828 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