• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

using wcf webservice results in a gridview in a vb app

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
share-copy-web.config
0
Mark Klein
Asked:
Mark Klein
  • 7
  • 2
3 Solutions
 
ambienceCommented:
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.
0
 
Mark KleinAuthor Commented:
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
0
 
Mark KleinAuthor Commented:
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?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
apeterCommented:
since you are running in the same machine . Are you running wcf service project  prior to  grid view second project ?
0
 
Mark KleinAuthor Commented:
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.
0
 
ambienceCommented:
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.
0
 
Mark KleinAuthor Commented:
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.
0
 
Mark KleinAuthor Commented:
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:
    <behaviors>
      <serviceBehaviors>
        <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>        
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehaviour">
          <webHttp/>
        </behavior>
        <behavior name="webEndpoint">
            <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Xml" 
                helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

Open in new window

What more is needed?
0
 
Mark KleinAuthor Commented:
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
0
 
Mark KleinAuthor Commented:
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.
        gvWebServiceData.DataBind()
        client.Close()

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#.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now