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

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.

Related

How can I get rid of the “The target assembly contains no service types” for self WCF hosted projects

I have a solution with several WCF self hosted projects. Every time i run a uni test i message box with this message pops up.
Because the projects were not created as WCF projects, they don't have the WCF tab in properties page were, according to many posts, i should be able to fix it by disabling option Start WCF Service Host when debugging another project in the same solution
I am running on VS 2017.
Any pointers?
Found out.
The problem was that i had a WCF Library project in the solution that was created as a regular Library project.
I fixed by adding the followin XML tag to the library project:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
<WcfProjectProperties>
<AutoStart>False</AutoStart>
</WcfProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
To get the tag, case anyone wonder what is it, i created an WCF library project on a dummy solution, uncheck the Start WCF Service host when debugging another project in the same solution as show in the picture below, and grab the tag from the config file.

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

Using ChannelFactory with WorkflowServiceHost

Is there a way to do the service inference on a workflow definition XAML to create an interface that can be distributed to the client to be used with ChannelFactory instead of the host exposing WSDL and the client having to generate a service definition by adding a service reference?
I did this in a three step process:
Temporarily exposing the metadata from the workflow service
Creating proxy code with svcutil
Changing configuration back to not exposing metadata
In detail:
Include your XAMLX file which defines the service in a project that was created as "WCF Workflow Service Application" (DeclarativeServiceLibrary1)
Compile the project
Set the project as startup project
Select xamlx file in Solution Explorer
Press Ctrl-F5 -> WCF Test Client starts, you see your service loaded
RightClick on the xamlx URL in WCF Test Client, choose Copy address (e.g. http://localhost:56326/Service1.xamlx)
Open a VS2010 Admin console window
Create the proxy code with svcutil.exe:
cd /D %TEMP%
svcutil http://localhost:56326/Service1.xamlx
This creates two files, a *.cs and a *.config, that contain the proxy code
I had a lot of problems with other ways of craeting the proxy code (inside VS2010), the external svcutil was the most stable way to do it. Hope this helps.

Adding WCF RIA Services class library to Silverlight 5 application

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.

How to use a WSDL file to create a WCF service (not make a call)

I have an old WSDL file and I want to create a server based on this WSDL file.
The WSDL is generated from a ASMX (I suppose but I am not sure).
How can I achieve this ?
original question where the OP thought he needed to create a client based on the WSDL.
Using svcutil, you can create interfaces and classes (data contracts) from the WSDL.
svcutil your.wsdl (or svcutil your.wsdl /l:vb if you want Visual Basic)
This will create a file called "your.cs" in C# (or "your.vb" in VB.NET) which contains all the necessary items.
Now, you need to create a class "MyService" which will implement the service interface (IServiceInterface) - or the several service interfaces - and this is your server instance.
Now a class by itself doesn't really help yet - you'll need to host the service somewhere. You need to either create your own ServiceHost instance which hosts the service, configure endpoints and so forth - or you can host your service inside IIS.
There are good resources out there if you know what to search for. Try "Contract First" and WCF. or "WSDL First" and WCF.
Here is a selection:
Basic overview of WSDL-First development with WCF and SvcUtil.exe.
WSCF - A free add-in to Visual Studio enabling Contract-First design with WCF
Introduction to WSCF
A walkthrough of using WSCF
The WSCF project page on CodePlex (WSCF is now open source)
Article on how to design "WCF-Friendly" WSDL
Use svcutil.exe with the /sc switch to generate the WCF contracts. This will create a code file that you can add to your project. It will contain all interfaces and data types you need to create your service. Change the output location using the /o switch, or you can find the file in the folder where you ran svcutil.exe. The default language is C# but I think (I've never tried it) you should be able to change this using /l:vb.
svcutil /sc "WSDL file path"
If your WSDL has any supporting XSD files pass those in as arguments after the WSDL.
svcutil /sc "WSDL file path" "XSD 1 file path" "XSD 2 file path" ... "XSD n file path"
Then create a new class that is your service and implement the contract interface you just created.
You could use svcutil.exe to generate client code. This would include the definition of the service contract and any data contracts and fault contracts required.
Then, simply delete the client code: classes that implement the service contracts. You'll then need to implement them yourself, in your service.
Using the "Add Service Reference" tool in Visual Studio, you can insert the address as:
file:///path/to/wsdl/file.wsdl
And it will load properly.