WCF Service reference from Silverlight Class Library - wcf

I have a Silverlight application communicating with the server side through WCF services. Initially I had everything in the main Silverlight application, but now I wanted to factor our some classes to a separate Silverlight Class Library project. This however gave me some odd issues...
I wanted to factor the classes that does the WCF communication out to a separate project. So I:
Created a new project; Silverlight class library
Moved the classes from my Silverlight application to my Silverlight class library
Removed the Service reference in the application as I no longer call it from the app.
Added a Service reference from the class library project.
Now - compiling is fine and I get intellisense for the service stuff in the Class Library, so it seems to be fine. I also updated the service and got the updates in the Class Library.
But when running the application it fails when doing a service call giving the following error:
InvalidOperationException was unhandled by user code
Could not find default endpoint element that references contract 'MyServiceReference.IMyService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Seems like it can't find the service, but why? I assume there should be no problem to have service references from a Silverlight Class Library as it allows me to add one?

IT can't find any service configuration - where do you have the config for the WCF service? By default, the client app (the EXE) will have a app.config that contains the service endpoints to connect to.
Also by default, class libraries (DLL's) don't have their own configuration but rely on their hosting app to provide the configuration for them.
So all in all - you're probably missing the config for the client endpoint. Most likely, it has been created as an app.config in the class library project, but that's not being used, really - you'll have to move the <system.serviceModel> section up to the main app's config (I'm not fluent in Silverlight, but you'll know where to put it).
Marc

Related

Incorrect WCF Service Reference / Empty Reference.cs file

I have created a WCF service using Service Library template. Using the Service.dll generated, I have hosted the service in a console application.
However, when I add a Service Reference in my web project, on viewing the Service details in Object browser, it points to incorrect assembly in the object browser as shown in the screen shot below.
One possible issue could be that, while renaming the namespaces in my web project, I ended up renaming the namespace of Service project also. But even after fixing all the namespaces, I still have this issue.
Any ideas on what can be done to resolve it?
While adding a Service Reference, it displays the correct members/interfaces as shown in the screenshot below. Only when I view the Service Reference in the object browser, I don't see those interfaces exposed by the service.
Project dependencies of service project
Not sure why the web project is a dependency of the Service library project? It should not be as I have not added any reference to it in the Service project.
I came across this question here after researching on this issue.
I also found out that the reference.cs file was empty in my case also. After unchecking Reuse types in referenced assemblies from 'Configure Service Reference' dialog, I was able to generate the Service reference client code successfully. My Service reference is now pointing to the correct Interface/members. In case of any queries, feel free to comment or contact me directly.

Must I add a WCF service class library in order to host a WCF Service in a Windows service?

I read about how to host Wcf Service in a Windows service. There is a guide here:
http://msdn.microsoft.com/en-us/library/ms733069.aspx
But what I did was just to create new WCF Service class and interface inside the same project of the Windows Service instead of creating a new project separatly for the Wcf service.
Is it possible to do it? because I can't add a service reference to that service from other projects in the solution. It can't find it.
OK, here is what I found.
Creating a new solution with one Windows service project with a Wcf service class and one Asp.Net folder.
Running the Windows service.
Trying to add a Service reference to the Asp.Net project.
Result: Service can't be found.
Adding a new project which contains a Wcf project to the solution.
Adding a reference to it from the Windows Service.
Trying to add a Service reference to the Asp.Net project.
Result: Service found.
Reading this link:
http://msdn.microsoft.com/en-us/library/ms731758.aspx it's done similar to what I did in the test solution, but still there is a need to write some code in the Windows Service.
In this link:
http://msdn.microsoft.com/en-us/library/ms731758.aspx
They show how to host it without creating a separate project.
So the answer to the question is no, you must not, but you have to write some code for hosting the service and can't just use the configuration file.
Note the windows service must be running so you can successfully add the reference.

WCF Service communicate with methods and DLL pointing to Class

As my title may be confusing, I am a little myself. If I have a WCF service running which calls methods from class MyDataAccessLayer and I also have a DLL which I use as a reference in my project that calls methods from MyDataAccessLayer, can this be the cause to this issue:
Could not find default endpoint element that references contract 'WCFTestService.ITestService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I am trying to understand WCF as much as possible, and I have checked the app.config file a thousand times and I have not seen any issues with my endpoint settings. Any thoughts?

WCF Service Reference name comes out as contract's name (interface), instead of the actual service name...?

Allow me to explain a little better.
I have a VS2010 Solution, split into 2 projects: a WCF Web Service, and a Class Library that uses the Web Service.
The WCF Web Service is a simple logging service; namespace "LogService", service "LogService", contract "ILogService".
When you use the "Add Service Reference" utility that comes with VS2010 to add a reference to the WCF, into the consuming Class Library project, you will see that the tool correctly adds a reference to a Web Service that can be called through "LogService.LogServiceClient". No problem here.
Now, I have another Solution; this is also split into 2 projects: another WCF Web Service, and a Web Application that uses this new Web Service.
This particular Web Service provides operations performed on a database; namespace "BLService", service "BLService", contract "IBLService".
Using that very same "Add Service Reference" utility in this project, however, adds a reference whose client name is actually "BLService.IBLServiceClient". Please notice there is a "I" prepended to the service client class name. The utility seems to have decided it should use the contract's name, instead of the service's name, to create the service client class.
I don't understand why does the tool behave differently on both Solutions. I've tried checking everything I could from both, and I can't find no significative differences (to my knowledge, at least).
Do you people know why does this happen? What things should I check, and correct, in my Web project (or anywhere else in the solution) so this odd behavior does not happen anymore?

How do I get the generated proxy class of a WCF service to implement INotifyPropertyChanged

Is it possible to have the proxy classes that are generated when setting a service reference implement INotifyPropertyChanged?
In this case it's a silverlight app referencing a WCF service?
Update:
The SlSvcUtil.exe commandline utility is part of the silverlight SDK installed {Program Files}\Microsoft SDKs\Silverlight\v4.0\Tools will generate the classes with an INotifyPropertyChanged implementation.
I'll leave this question up, as I live in hope that someone will say this is possible from Visual Studio without haing to launch an external tool.
Proxy classes do not implement that interface, only DataContracts do. If you open .svcmap file generated by adding service reference in XML viewer you can change EnableDataBinding element to true and update service reference from VS. I thought that true is default value and you have to manually changed it if you don't want to use INotifyPropertyChanged. What is so specific in your service?