Adding WCF RIA Services class library to Silverlight 5 application - wcf

Trying to add WCF RIA Services class library to my SL5 app in VS 2010 but once I set the WCF RIA Services Link in class library properties, project fails to build with numerous "The type or namespace name 'QueryResult' could not be found", 'EntitySet', EntityQuery' errors...
I'm following the MSDN Walkthrough Walkthrough: Creating a RIA Services Class Library trying to port a subset of my WPF app to SL5 so I first created an SL5 application with RIA checkbox uncheked which created two projects:
MySLApp (Silverlight 5)
MySLApp.Web (.NET 4)
Once I had that in place I added WCF RIA Services class library which created another two projects:
MySLAppWCF (Silverlight 5)
MySLAppWCF.Web (.NET 4)
In MySLAppWCF.Web I created an ADO .NET Entity Data Model and added a Domain Service Class using an entity from the Data Model. At this point all these new projects buid fine so I added a reference to MySLAppWCF in my MySLApp project and a reference to MySLAppWCF.Web in my MySLApp.Web but the final step to get all this wired up is to set the WCF RIA Services Link in MySLAppWCF to MySLAppWCF.Web but once I do that it all blows up with numerous "The type or namespace couldn not be found" errors. I checked the references in the library and there is a reference to System.ServiceModel there.
Any ideas on how to get all this working?
EDIT: I kept digging and found something about adding a reference to System.ServiceModel.DomainServices.Client library which is located in RIA SDK so I did that and it took care of the original errors but now I'm getting WebDomainClient and DomainServiceFault not found in my MySLAppWCF project even after adding a reference to System.ServiceModel.DomainServices.Client there as well and these two appear to be in that namespace...

Both WebDomainClient and DomainServiceFault are definied in System.ServiceModel.DomainServices.Client.Web (usually found at C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.Web.dll)
You need to add a reference to this assembly too.
Let me assert that your design could bring you to some problems, having two different sites (one that host the SL application and one to host the domainServices) it's unusual and could bring you in cross-request problem, if it isn't needed I suggest you to transform MySLAppWCF.Web into a normal DLL and reference it from your host.
Also, pay attention at the web.config of MySLAppWCF.Web, VS has modified it in order to use the needed DomainServiceModule.

Related

Add service reference creates client without methods

Hi when I trie to create a client for wsdl service (this one: http://webapi.aukro.cz/uploader.php?wsdl) the "add service reference" in VS 2012 creates a client that has no methods in it.
Ive tried to create a test connection on this service in the wcftestclient app and most of the generated methods are marked as errors with message "This opertion is not supported in wcftestclient because it uses type xy", where xy is some type from the service.
Edit: Ive been trying to do this in a windows store app...
Edit2: Ive just tried to add reference in a "windows class library" project at it works without any problems. "Portable class library" project is no go so far.
Any ideas?
I managed to solve a similar problem by doing the following:
Check your Service Reference. Right-click and "Configure Service
Reference". Uncheck "Reuse types in referenced assemblies" and let it
rebuild the proxies.
Source: https://stackoverflow.com/a/33422442/4695159

How to turn a basic class library into a WCF Service Library

I was trying to copy the functionality of an existing WCF service library to use it as a template for a new WCF service library. Since I was going to cut and paste all the code that I needed, and I didn't want it to create the default service stubs, I didn't start it by using the built-in "WCF Service Library" project template. I just added a new blank project to my solution, using the "Empty Project" template.
I then created two new blank .cs code files to my project to hold the interface and class for my service, and copied/pasted the Interface and Class code from my original WCF service library project, and made the alterations that I needed to make.
The new project compiles fine, however...
1) If I go into the project properties, the "WCF Options" section does not appear, as it does in my original WCF service library.
2) With the original WCF service libary project, I could right-click on it and select Debug->Start New Instance, and it would automatically start it using WCF Service Host. With the new project, if I try that, it says, "A project with an Output Type of Class Library cannot be started directly".
How do I get Visual Studio (I'm using 2012 Professional) to see this project as a true WCF class library, short of starting over and using the "WCF Service Library" project template?
You are missing the ProjectExtensions section from your project file
This is from one of my VS2010 projects.
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
<WcfProjectProperties>
<AutoStart>True</AutoStart>
</WcfProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
If I remove it, the WCF Options properties section goes away.
EDIT:
I did a comparison of an Empty project to a WCF Service Library, and found that you also need to add this to your project to get the WCF Options to appear in the project properties
<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
There is another entry in WCF (and not in the Empty project)
<StartArguments>/client:"WcfTestClient.exe"</StartArguments>
which I'm assuming is needed when you do the
Debug->Start New Instance
There is other stuff that you will need however, such as a reference to System.ServiceModel.
To be honest, I think you'd be better off using the proper WCF Service Library template and cutting out stuff you don't want, rather than trying to figure out what you do need.

WCF Enterprise Library ExceptionHandling failing when faultcontracttype in other project

Background: I have a WCF project that is using Microsoft Enterprise Library WCF Exception Handling.
We recently decided to move our operation and data contracts into a separate project (.net assembly) called comanynamespace.xxx.WCF.Utilities. After moving the operation and data contracts, I changed the faultContractType namespace to reflect the new assembly.
Now when I launch the web service in VS2010 I get the following error:
Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "WCF Exception Shielding"
I have tried: ensuring the same references exist in both projects and ensuring that both projects are running under .net 4 (no client modes), etc. Neither helped resolve the issue.
Finally, I copied the Service Fault class back into the Web Service project and changed the namespace in the web.config to point back to the local namespace:
from:
faultContractType="comanynamespace.xxx.WCF.Utilities.ServiceFault, comanynamespace.xxx.WCF.Utilities.Services"
to:
faultContractType="comanynamespace.xxx.Web.Services.ServiceFault, comanynamespace.xxx.Web.Services"
This does resolve the error, however, now I must have my service fault data contract in both locations.
Does anyone know why I am unable to use a service fault (data contract) in another .net assembly with Microsoft EL WCF Exception Handling?
The problem ended up being that the namespace (second part) of the faultcontracttype was set to
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities.Services"
instead of
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities"
companyname.xxx.WCF.Utilities is the namespace for the assembly.

Error message from svcutil.exe - what does it mean?

I've had not a lot of luck creating a WCF service with Visual Studio. It's in IIS, and it I click 'browse' on the .svc file itself, it tells me I have created a service. So I assume it's all okay to a point.
Throughout my time I came across a recommendation to use a program called svcutil.exe. I used it on my service and got the following error. I don't know what it means, so hopefully someone can shed some light on the situation.
Here's the result:
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'http://localhost/EvalServiceSite/Eval.svc'
using WS-Metadata Exchange or DISCO.
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.Se
rviceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://tempuri.org/' could not be found.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:portType[#name='IEvalService']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is de
pendent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/
']/wsdl:portType[#name='IEvalService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:binding[#name='BasicHttpBinding_IEvalService']
Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is depend
ent on.
XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:binding[#name='BasicHttpBinding_IEvalService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:service[#name='EvalService']/wsdl:port[#name='BasicHttpBinding_IEvalServi
ce']
Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata docu
ments did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assembl
ies. Verify that you passed all the metadata documents to the tool.
Warning: If you would like to generate data contracts from schemas make sure to
use the /dataContractOnly option.
I think this previous Stack Overflow question may help with your current question but not necessarily your problem.
Error: Cannot import wsdl:port with svcutil
You've created your WCF service and you've browsed to it in IIS so you're happy that it is working. The purpose of SVCUtil.exe is to generate classes that you can use in an application to interact with the service with compile time information on the contract members and methods.
it performs the exact same function as adding a service reference in visual studio to consume the service.
If your having trouble, i'd suggest just creating a simple console project in visual studio, adding a service reference and giving it the url of the service you've hosted in IIS. Then click "show all files" in the visual studio solution explorer and look at the reference.cs file it gives you. This will show you what information has been consumed from your service.
Edit
Hi Again,
After going through all the comments below I'm starting to see more about your problem. I think you misunderstand what it is your doing when in fact you've already achieved what you want to achieve.
The original project, the one you had with the WCF test client that worked did what you needed. It is a fully fledged WCF Service. All you needed to do was right click the solution in visual studio and publish it. If you then make sure that you make an IIS virtual directory point at your solution, through the publish wizard. Then when you run your project and then browse to that url, that will give you a service to consume for testing purposes.
What you are doing at the moment, creating a WCF project, adding that DLL to a website project is fundamentally wrong: The example you followed, presumably this one :
http://msdn.microsoft.com/en-us/library/ms733766.aspx
is about creating a WCF service in a web site project from scratch. Not about adding a pre-existing WCF project and hosting it.
Your essentially trying to do one thing in two different ways together.
Your current course of action is to either remove the DLL in your web project and then create the service there. Or host your current WCF service in IIS ( the project you downloaded from me or your original one)
At this point you have a hosted service. Then usually you have an application to interact wtih it. This you found using svcutil and can be done in one of two ways:
You create the console application and do "Add Service Reference" to the URL you have hosted in IIS.
Or you use SVC Util.exe point it at the url which generates a class file you include in your console / application.
I hope that clears things up about WCF and what stages to use various tools?
Edit 2
Just in case you don't get to the Chat:
I still think theres something wrong with your original project. I'm not sure what you mean by the one with the DLL either? if that means your website project with the dll of the WCF project, then no not that one.
I've taken the project I sent you earlier. I've hosed that in IIS so that when i browse to localhost/EvalService on my machine i get the standard
"EvalService Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:"
Once I had that set up i created a console application, "added service reference" in visual studio and it consumed teh service no problem.
Try doing the above with the project I sent you and see how far you get.

Can't get up with RIA demo

Based the article I've tried to start-up the RIA services.
At the moment there are 2 blockers:
On the client side I don't have
<datagrid:DataGrid component. Does
anybody know what namespace contains
this object? (already resolved with
Silverlight Toolkit usage, thanks to
Refracted Paladin for help)
On the
client side I don't have access to
my DomainService... don't know why. Also, I con't see "System.ServiceModel.DomainServices.Client" assembly available to be added to the projects references.
Could anybody help to resolve the 2nd problem?
Thank you.
P.S. I have VS2008, SP1, Silverlight, RIA Services installed.
System.ServiceModel.DomainServices.Client is part of the RIA Services RC for SL4/VS2010. The DLL's for RIA Services RTW for SL3/VS2008 are completely different. And to my knowledge, they can't be installed side-by-side - I have tried.
This article points out some of the differences between the 2 versions, and how to move to RIA Services for SL4/VS2010: http://jeffhandley.com/archive/2010/03/15/contososales-mix10.aspx
If you do end up installing RIA Services for SL4/VS2010, you access the "System.ServiceModel.DomainServices" namespace with a reference to "C:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.dll".
Guess, the problem was in some mistery (my machine has different issues last few days). As a results my ReSharper wasn't able to find the class in a namespace that was not mentioned in the "using" section.
At the moment domain service is accessible on the client side of my Silverlight app. I clicked "Show All Files" for the Silverlight project and found 'Generated_Code' folder that contained all required generated files. In that file full class name is specified, I've used it in my pages and all is workable now.
Thanks to all.