Some More WCF and silverlight questions

mic_y

Expert Member
Joined
Dec 23, 2004
Messages
1,646
Reaction score
10
Location
Slaapstad
Hey guys... so I turn to the wealth of knowledge that you have once again.

I have a silverlight application that I am developing, and it is pulling data from a SQL Server database using a WCF webservice...

Now after battling to get this working for 3 days, I am just about ready to give up.

Basically, I am doing the following (all code is in VB as that is all I know ;))

The code for IService1.vb
Code:
' NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
<ServiceContract()> Public Interface IService1

	<OperationContract()> Function GetFinesByStudentNo(ByVal strStudentNo As String) As List(Of WebFine)

End Interface

<DataContract()> Public Class WebFine
	Private _FineNo As String
	Private _VehReg As String
	Private _FineDate As Date
	Private _FineStatus As String
	Private _FineTotal As Double

	<DataMember()> Public Property FineNo() As String
		Get
			Return _FineNo
		End Get
		Set(ByVal Value As String)
			_FineNo = Value
		End Set
	End Property
	<DataMember()> Public Property VehReg() As String
		Get
			Return _VehReg
		End Get
		Set(ByVal Value As String)
			_VehReg = Value
		End Set
	End Property
	<DataMember()> Public Property FineDate() As Date
		Get
			Return _FineDate
		End Get
		Set(ByVal Value As Date)
			_FineDate = Value
		End Set
	End Property
	<DataMember()> Public Property FineStatus() As String
		Get
			Return _FineStatus
		End Get
		Set(ByVal Value As String)
			_FineStatus = Value
		End Set
	End Property

	<DataMember()> Public Property FineTotal() As Double
		Get
			Return _FineTotal
		End Get
		Set(ByVal value As Double)
			_FineTotal = value
		End Set
	End Property
End Class

The code for service1.vb:
Code:
Imports WITS.Kaleidoscope.ParkingLogic
Imports WITS.Kaleidoscope.BusinessEntity

' NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
Public Class Service1
	Implements IService1

	Public Function GetFinesByStudentNo(ByVal strStudentNo As String) As List(Of WebFine) Implements IService1.GetFinesByStudentNo
		Dim perPermitHolder As PermitHolder
		perPermitHolder = ParkingLogic.GetPermitHolderByCriteria("Student_StaffNo = '" & strStudentNo & "'", "")(0)
		If perPermitHolder Is Nothing Then
			perPermitHolder = ParkingLogic.GetPermitHolderByCriteria("IDNumber= '" & strStudentNo & "'", "")(0)
		End If
		Dim result As EntityCollection(Of Fine)
		result = ParkingLogic.GetRelevantFines(perPermitHolder)

		Dim x As New List(Of WebFine)

		For Each theFine As Fine In result
			Dim aFine As New WebFine
			With aFine
				.FineNo = theFine.FineNo
				.FineStatus = theFine.FineStatus
				.FineTotal = theFine.FineTotal
				.VehReg = theFine.VehRegistration
				.FineDate = theFine.FineDate
			End With
			x.Add(aFine)
		Next
		Return x
	End Function
End Class

I have tested the service using WcfTestClient and it works perfectly, returning the data that is needed...

The code for MainPage.xaml.vb:
Code:
	Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
		Dim WebSerivce As ServiceReference1.Service1Client = New ServiceReference1.Service1Client
		AddHandler WebSerivce.GetFinesByStudentNoCompleted, AddressOf WebSerivce_GetFinesByStudentNoCompleted
		WebSerivce.GetFinesByStudentNoAsync(txtUserID.Text)
	End Sub

	Private Sub WebSerivce_GetFinesByStudentNoCompleted(ByVal sender As Object, ByVal e As ParkingFinesSilverlight.ServiceReference1.GetFinesByStudentNoCompletedEventArgs)
		dgFines.ItemsSource = e.Result

... ETC do other stuff...

Now, I have published the Webservice to my local IIS server, and added it as a service reference to the silverlight project under address http://localhost/Service1/Service1.svc. It was discovered and there seemed to be no issues with that part.

When I click the button nothing happens. When looking through the IIS logs, I do not see any requested (I am not sure whether they should be there or not). Basically, I dont see the datagrid populated, nor the rest of the code that is meant to be executed by the app (have some animation type stuff).

Any help would be greatly appreciated.

Cheers,
Michael
 
This might not be the problem but will cause problems later:

If you referenced your service on "localhost" from your silverlight application it might work on your dev machine, but most definitely won't work on any others.

You must remember that your silverlight application is downloaded to your client's machine and executed there, not on the server side. Which means your silverlight application would go looking for the service on your client's machine. ;)

You're going to need to change the reference in the "ServiceReferences.ClientConfig" file manually after you've published it to a static IP which points to your IIS website.

Hope it helps!
 
Heya, I'd suggest you should look at something simple such as WCF Web Service on Code Project.

I'm not a VB developer. The idea behind WCF Services is that a Client is created for every call, the channel is opened and should be closed afterwards.
ex.
var factory = new ChannelFactory<IService1>(); <- Multiple possible parameters here + default, also use the factory to set credentials, specify endpoints etc. (endpoints should be configured via your application configuration file)
IService1 = factory.CreateChannel();
IService1.CallMethod();
try{ ((IChannel)IService1).Close(); } catch(CommunicationObjectFaultedException) { ((IChannel)IService1).Abort(); }

Perhaps it might solve the issue you have, but there might be issues regarding the service now hosting the web service and that it doesn't have permissions (ex. NetworkService) or even perhaps an issue regarding certificates.
Hard to tell with the information provided though, hope you get it working! :) Ciao
 
Top
Sign up to the MyBroadband newsletter
X