Solved

Accessing WCF in Windows7 Phone Silverlight App

Posted on 2011-03-24
31
1,259 Views
Last Modified: 2013-12-27
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?
0
Comment
Question by:markej
  • 17
  • 14
31 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35205993
when you have added the service reference, which name have you provided it? do you at least see ServiceReference1?
0
 

Author Comment

by:markej
ID: 35206284
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
 

Author Comment

by:markej
ID: 35206356
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35206477
are you sure you added the service reference to the Silverlight application?
0
 

Author Comment

by:markej
ID: 35206653
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35206746
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
 

Author Comment

by:markej
ID: 35207005
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35207056
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
 

Author Comment

by:markej
ID: 35207253
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35207346
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
 

Author Comment

by:markej
ID: 35207499
Unfortunatly This application doesn't like the file extensions for the files so it isn't letting me upload.

0
 

Author Comment

by:markej
ID: 35207653
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35207792
why do you have an empty Service1Client.vb file in your silverlight app?
0
 

Author Comment

by:markej
ID: 35207881
I don't know, should it be there and what should it have in it?
0
 

Author Comment

by:markej
ID: 35207903
Could have been done by intellisense, trying to fix the problem
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35207904
remove it
0
 

Author Comment

by:markej
ID: 35208174
removed
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35209100
and did it help?
0
 

Author Comment

by:markej
ID: 35209124
nope
0
 

Author Comment

by:markej
ID: 35209143
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35209350
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35211755
I cannot open your solution (service). It complains about missing files (application.designer.vb, web.config, assemblyinfo.vb, resources.designer.vb)
0
 

Author Comment

by:markej
ID: 35211894
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35211914
have you created a solution containing both project? this is the usual way of developing.

can you zip your full solution?

0
 

Author Comment

by:markej
ID: 35212028
0
 

Author Comment

by:markej
ID: 35212060
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
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 35214062
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
 

Author Comment

by:markej
ID: 35214304
the serviceReference.ClientConfig file is empty what do I need to add to that?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35214663
open the "configure service reference" dialog.
change the collection type to "System.Collections.Generic.List"
uncheck "reuse types in referenced assemblies"
0
 

Author Comment

by:markej
ID: 35215747
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35215914
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

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

18 Experts available now in Live!

Get 1:1 Help Now