Link to home
Start Free TrialLog in
Avatar of Mark Klein
Mark KleinFlag for United States of America

asked on

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
SOLUTION
Avatar of ambience
ambience
Flag of Pakistan 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
Avatar of Mark Klein

ASKER

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
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?
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
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.
ASKER CERTIFIED 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
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.
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?
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
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#.