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

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.

Related

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.

Configure SSRS delivery extension for invoking a WCF service

Have created a custom delivery extension in SQL Server Reporting Services (2008 R2). Within the custom delivery I am making a call to a WCF service. Am not sure where to put the app.config settings for the WCF bindings.
Have tried adding the entire 'system.serviceModel' section into the Reporting Server config file (rsreportserver.config). Have also added the generated app.config file from the custom DLL into the report server's /bin folder. Am still getting the following error though.
Could not find default endpoint element that references contract 'name of my WCF service' 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.
For now I am changing the code to create the bindings through code but would rather have this config file based. Any help is greatly appreciated.
Thanks
David
A. I would just create a proxy class of SSRS service objects in code.
B. Then make your own wrapper code for creating a report or getting report info. I explained this in another question here:
Programmatically Export SSRS report from sharepoint using ReportService2010.asmx
C. Then build a service around those wrapper methods to get your data.

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.

Namespace Issue with WCF Data Contract / Design Problem?

I am having multiple Services in my application.i have a datacontract that i need to use in more than 1 service.
Eg: class myCommonClass is being used in 2 of my services service1 and service2
To do this, at a service level, i have a MyApplication.Common library and this library contains myCommonClass. Since both my services have a reference to MyApplication.Common, they can both use it.
My client application has service references to both service1 and service2.
To my client application, service1.myCommonClass is a separate namespace as compared to service2.myCommonClass and therein lies my problem
In my Reference.cs (generated via svcutil - the namespace of BOTH classes is the same i.e.
System.Runtime.Serialization.DataContractAttribute
(Name="MyCommonClass", Namespace="http://A.B.MyCommonClassNamespace")])
However, both of these are in 2 separate reference.cs files and the namespaces in the reference.cs is different due to being part of two separate service references.
Hence, to my client application they appear as two completely unrelated classes.
*Question 1 * : Is there any way that can i indicate to my client application that service1.myCommonClass and service2.myCommonClass are inherently the same class?
*Question 2 * : Is there something inherently wrong with my design here for me to run
into this problem?
No, your design is fine. Instead of adding service reference from Visual Studio, generate the proxy class using svcutil on the command prompt. Create a class library project and add the generated .cs files to it. You can create a batch file and run it in pre build step as well.
Use svcutil as below to generate the proxy class in a single file from service dll (the dll that implements your two service)
svcutil.exe /t:metadata "PATH\service1.dll" "PATH\service2.dll"
svcutil.exe /t:code *.wsdl *.xsd /o:Proxy.cs

How can I consume a WCF service using a local WSDL file?

I need to consume a WCF service based on a (preferably single) wsdl file.
The environment is VS-2008 (sp1), and I will be using a customized "Add Service Reference" macro to generate an error handling proxy. I want to be able to do this, by supplying a WSDL file that I get from the service provider (I do not want to supply a host URL).
How can this be done?
Sure - you can copy the path+filename for the WSDL and paste that into the "Add Service Reference" dialog box in Visual Studio (or just type int the full path + WSDL file name).
Alternatively, you can use the svcutil.exe command line utility to convert the WSDL file to your client proxy class.