Accessing WCF in Windows7 Phone Silverlight App

I've been following this code example http://www.cabotsolutions.com/2011/03/windows-mobile-7-app-development/ converting it to VB.Net as I go and have a problem,

I've created a WCF service added a service reference to it in my code, BUT when I try to access it in the "mainPage.xaml.vb"  I get an error in the line "Dim addClient As New ServiceReference1.Service1Client()" and a message saying the "ServiceReference1.Service1Client()" is not defined

What have I done wrong OR what extra do I need to do?
markejAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
You have 4 warnings that prevent your service from being able to be referenced:
Warning      4      Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.      C:\Temp\test2\WindowsPhoneApplication1\Service References\ServiceReference1\Reference.svcmap      1      1      WindowsPhoneApplication1

check http://msdn.microsoft.com/en-us/library/dd470100(VS.96).aspx
0
 
Éric MoreauSenior .Net ConsultantCommented:
when you have added the service reference, which name have you provided it? do you at least see ServiceReference1?
0
 
markejAuthor Commented:
I've followed the example mentioned above although I've converted the code to VB.Net, I'm using VS2010 and in the project's solution Explorer I can see the service References folder and within that "ServiceReference1" However when I try to reference that in the code I get the error.

This effects both the Delete  and Save_Click methods and also on the ViewPage.xaml it's the same,  Even when I try typing it in there is noreference to it in the inline code assistance window.

Here is the code:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Controls



'Namespace WindowsPhoneApp
Partial Public Class MainPage
    Inherits PhoneApplicationPage
    ' Constructor
    Public Sub New()
        InitializeComponent()

    End Sub
    ''' <summary>
    '''
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Save_Click(sender As Object, e As RoutedEventArgs)
        Dim fname__1 As String = FName.Text
        Dim lname__2 As String = LName.Text
        Dim age As String = SAge.Text

        FName.Text = ""
        LName.Text = ""
        SAge.Text = ""

        Dim addClient As New ServiceReference1.Service1Client()
        addClient.getDetailsAsync(fname__1, lname__2, age)
        MessageBox.Show("Saved...!!!")

    End Sub
    ''' <summary>
    '''
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub View_Click(sender As Object, e As RoutedEventArgs)
        Me.Content = New ViewPage()

    End Sub
    ''' <summary>
    '''
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Delete_Click(sender As Object, e As RoutedEventArgs)
        Me.Content = New DeletePage()

    End Sub
End Class
'End Namespace
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
markejAuthor Commented:
Sorry, Just reread your question, When I opened the add Service Reference window I added the following "http://localhost:58248/Service1.svc" in the Namespace window I left the default as "ServiceReference1" I clicked OK and it added it to the project and as I said I can see the reference in the solution Explorer, just can't reference it in the code it just underlines in blue with the notdefined error.
0
 
Éric MoreauSenior .Net ConsultantCommented:
are you sure you added the service reference to the Silverlight application?
0
 
markejAuthor Commented:
I thought I was, I Right clicked on the project title and selected "Add Service Reference" everything else is as described above, I also have a folder inside the project directory Titled ServiceReference1 and has a collection of files in it.
0
 
Éric MoreauSenior .Net ConsultantCommented:
is the service is compiling without a problem?

when you type ServiceReference1. do you still the intellisense poping? I see that the example has a MyTestService namespace (like all C# classes have).
0
 
markejAuthor Commented:
It doesn't show in intellisense (couldn't remember what it was called earlier) The code shown is what I've converted from the example I was trying at http://www.cabotsolutions.com/2011/03/windows-mobile-7-app-development/#comment-2622 I've also tried adding/removing the namespace.

Just retried compiling the service successfully. The references to the wcf service are the only TWO areas showing as errors.

I've tried deleting/adding the service a couple of times to see if something was missing BUT no luck.

Mark


0
 
Éric MoreauSenior .Net ConsultantCommented:
I cannot try this code as I don't have VS2010 on the PC I am currently. It makes no sense that the intellisense is not showing up if you are using the correct name.
0
 
markejAuthor Commented:
I can zip up the files and add them here so you can see them or alternatively if you tell me what to look for I can have a look in the serviceReference1 folder and look at those files.

How can I check the name?
0
 
Éric MoreauSenior .Net ConsultantCommented:
as I told already, I don't have VS2010 installed here.

you can zip it and upload it here. I may have time later tonight or tomorrow
0
 
markejAuthor Commented:
Unfortunatly This application doesn't like the file extensions for the files so it isn't letting me upload.

0
 
markejAuthor Commented:
WindowsPhoneApp.zip MyTestService.Publish.zip

I've uploaded the files in these TWO zips, the ones with the problamatical extensions have had ".txt" added to them.
0
 
Éric MoreauSenior .Net ConsultantCommented:
why do you have an empty Service1Client.vb file in your silverlight app?
0
 
markejAuthor Commented:
I don't know, should it be there and what should it have in it?
0
 
markejAuthor Commented:
Could have been done by intellisense, trying to fix the problem
0
 
Éric MoreauSenior .Net ConsultantCommented:
remove it
0
 
markejAuthor Commented:
removed
0
 
Éric MoreauSenior .Net ConsultantCommented:
and did it help?
0
 
markejAuthor Commented:
nope
0
 
markejAuthor Commented:
Have these errors still:
Error      7      Custom tool error: Failed to generate code for the service reference 'ServiceReference1'.  Please check other error and warning messages for details.      C:\inetpub\wwwroot\aspnet4\Windows7 Mob\WindowsPhoneApp\Service References\ServiceReference1\Reference.svcmap      1      1      WindowsPhoneApp
Error      46      Type 'ServiceReference1.Service1Client' is not defined.      C:\inetpub\wwwroot\aspnet4\Windows7 Mob\WindowsPhoneApp\MainPage.xaml.vb      39      30      WindowsPhoneApp
Error      47      Type 'DeletePage' is not defined.      C:\inetpub\wwwroot\aspnet4\Windows7 Mob\WindowsPhoneApp\MainPage.xaml.vb      59      26      WindowsPhoneApp
0
 
Éric MoreauSenior .Net ConsultantCommented:
the first error you need to fix is the first one.

completely remove the reference to your service, delete all folder and generated code, comment out your code that use the service.

once your silverlight app will compile without the service, try to add your service reference.

once your service will be added without any errors, then uncomment your code.
0
 
Éric MoreauSenior .Net ConsultantCommented:
I cannot open your solution (service). It complains about missing files (application.designer.vb, web.config, assemblyinfo.vb, resources.designer.vb)
0
 
markejAuthor Commented:
I have followed your instructions compiled the app successfully and then tried adding the serviceReference1 back in as soon as I do that I get the same error:

Error      46      Custom tool error: Failed to generate code for the service reference 'ServiceReference1'.  Please check other error and warning messages for details.      C:\inetpub\wwwroot\aspnet4\Windows7 Mob\WindowsPhoneApp\Service References\ServiceReference1\Reference.svcmap      1      1      WindowsPhoneApp

I guess the question is now, What is this error and how do I fix it?

Mark
0
 
Éric MoreauSenior .Net ConsultantCommented:
have you created a solution containing both project? this is the usual way of developing.

can you zip your full solution?

0
 
markejAuthor Commented:
0
 
markejAuthor Commented:
I have an existing soluttion I created both projects in. The file I've uploaded is the wCF project with some extensions changed to .txt to allow upload.

This application won't let me upload the WindowsPhoneapp.zip  so I have attached a zip containing the files that are in addition to the file I supplied earlier



missing-files.zip
0
 
markejAuthor Commented:
the serviceReference.ClientConfig file is empty what do I need to add to that?
0
 
Éric MoreauSenior .Net ConsultantCommented:
open the "configure service reference" dialog.
change the collection type to "System.Collections.Generic.List"
uncheck "reuse types in referenced assemblies"
0
 
markejAuthor Commented:
That has allowed the intellisense to recognise the wcf service however the ServiceReference.ClientConfig file is still empty except for the following "<configuration />" The application now compiles and runs although when I try the Save feature which calls the Getdetails call I get a "KeyNotFoundException was unhandled" error on the Sub New procedure in the ServiceReference1 Reference.vb file.

Is this due to the empty config or something else and what can I do to fix it, I had assumed the sample I was following worked and as I had compilied the vb.net version.
0
 
Éric MoreauSenior .Net ConsultantCommented:
now it is something else and I don't have to debug this. Have you tried the C# sample to see if it is working (or maybe it has the same problem)? Have you tried to contact the author of the article?
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.

All Courses

From novice to tech pro — start learning today.