Exporting XSD and WSDL from WCF Service (SVCUTIL) - wcf

I have a Wcf Service with a simple method. I need to generate the WSDL and XSD file, to handover to third-party that needs to use the webservice.
The solution is done in Visual Studio 2013, .NET 4.5. From the BIN folder, I run the SVCUTIL /t:metadata {name of dll file}. Shortly after I now have both a WSDL and a XSD file. The WSDL file contains:
[SAPI XML] tempuri.org.wsdl(2): unknown tag <wsdl:definitions>.
[SAPI XML] Compulation Failed!
[W3C XML tempuri.org.wsdl(2) : The name of the root element in the grammar must be "grammar", not "definition".
[W3C XML] Compilation Failed!
It's almost the same output for the XSD file.
Any ideas?
ThanTheks
Frank

Loaded the project in VS2012 (on another PC), build and ran the SVCUTIL.EXE - this time no problems. Maybe related to the SVCUTIL installed on my VS2013 installed PC.

Related

Generate C# Class with svcutil.exe against xsd using External tools in VS 2012

I have created a C# Data Contract class against XSD and used my WCF service. And I have setup the xsd.exe using Visual Studio External Tools like below,
Use bat file with:
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"
xsd %1 %2 /classes /language:CS
and then used bat file in external tools.
Title : XSD
Command :C:\Tools\bin\xsd.bat
Arguments : "$(ItemPath)" "/outputdir:$(ProjectDir)"
to this setup I am getting a class file in my project directory.
So, My question is how to set up same kind of external tools in visual studio for SVCUTIL.EXE tool.
please suggest the better ways of doing..
I am having a XSD file and I need pure Data Contract c sharp class for this.
I have tried SVCutil.exe tool in command line option.
svcutil.exe "E:\Test.xsd" /dconly
Getting this error:
Error: Type 'LoadReference' in namespace '' cannot be imported. Complex types with simple content extension are not supported. Either change the schema so that
the types can map to data contract types or use ImportXmlType or use a different serializer.
It seems like this tool not supporting complex types.
Thanks in advance...

How to publish WCF Service Library and get transformed web.config?

I have WCF Service Library project and have configured slow cheetah extension for transforming .config files.
When I run publish on the project the build output produce in bin folder appropriate dll file for the service and NameOfService.dll.config file which is transformed correctly.
The publish process also produce .svc and web.config file. The issue is that the web.config file is not transformed.
Is it possible to get also web.config file transformed by this process and how ?

troubles with generating a service reference

I have to build a .Net application that consumes a bunch of web service. This web service runs under weblogic. The WSDL of the web services mention a XSD file that describes the types.
When I try to add a "Service reference" with VS studio, I have some errors :
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://mycustomer/ws/types' could not be found.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://mycustomer/ws/wsdl']/wsdl:portType[#name='lbWebPT'] C:\Projects\mycustomerproject\Service References\ClientService\Reference.svcmap
X3 for the portType, Binding and port elements of the wsdl file.
I was guessing this was because of the missing types defined in the xsd file. To workaround this error, and also to avoid duplicate code, I run the following command on my xsd file (in a pre-build event command line) :
"%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin\xsd.exe" "$(ProjectDir)xsdofmycustomer.xsd" /namespace:"MyCustomer.WebServices.Types" /c /o:"$(ProjectDir)."
this command successfully produces a code file with the types and with the correct namespace defined in the XmlRootAttribute.
this code has been put a dedicated VS project. The project where I'm trying to reference the service reference this project. However, the error is still occurring.
What can I do to solve my problem ?
PS: I was able to partially solve my problem using svcutil.exe pathtowsdl pathtoxsd, but I'd like to be able to maintain the reference in VS for ease of use.
thx
I'm not a fan of using project Service References because of the cruft the proxy generator inserts by default. But, if you really want to use Service References for your project then you need to merge the contents of the wsdl & xsd files into a single file. The Service Reference UI assumes all the data it needs to generate the proxy is in the file you give it. SvcUtil is more flexible as you found out. You should able to replace the wsdl:import element with a wsdl:types element that contains the xsd file contents (without the xml directive of course). Next, you enter the path to the file in the address textbox of the Add Service Reference dialog and you should be good to go with Visual Studio catered proxy goodness.

F# WSDL code generation

I'm using VS.NET 2010 integrated shell with F# and I'm trying to consume a soap web service... How do I go about generating F# source? I tried
wsdl l:"C:\Program Files (x86)\FSharpPowerPack-2.0.0.0\bin\FSharp.Compiler.CodeDom.dll" http://localhost/?wsdl
Along with
wsdl /language:"Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider, Microsoft.FSharp.Compiler.CodeDom, Version=1.9.2.9, Culture=neutral, PublicKeyToken=a19089b1c74d0809"
However I can't seem to get the /language switch to work.
EDIT:
taspeotis' answer got me going... This generated F# source for the web service:
gacutil -i "C:\Program Files (x86)\FSharpPowerPack-2.0.0.0\bin\FSharp.PowerPack.dll"
svcutil /language:"Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider, FSharp.Compiler.CodeDom, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a19089b1c74d0809" http://localhost/?wsdl
Have you added FSharp.Compiler.CodeDom.dll to the GAC? Use gacutil.exe to do this.
3rd party edit
Here an example gacutil.exe /l System.XML.Linq to list certain assemblies.
Besides to FSharp.Compiler.CodeDom (source) an alternative might be the FSharp.Data library
Quote from jizugu: This generated F# source for the web service:
gacutil -i
"C:\Program Files (x86)\FSharpPowerPack-2.0.0.0\bin\FSharp.PowerPack.dll"
svcutil
/language:"Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider
,FSharp.Compiler.CodeDom, Version=2.0.0.0, Culture=neutral
,PublicKeyToken=a19089b1c74d0809" http://localhost/?wsdl
This doesn't answer your question, but you may have better luck generating C#, compiling that C# into a library DLL, and referencing that DLL from your F# code. (The C# compiler csc.exe will be part of your .NET installation.)
I would be surprised if the F# Code DOM provider worked with WSDL. I wrote the initial implementation some time ago while at Microsoft and we got it to work with ASP.NET, but unless it has been improved since then, it probably won't work with WSDL or XSD.
Even for ASP.NET, we had to create a separate class that included some ASP.NET specific "hacks". This was partly because the CodeDOM generated by ASP.NET was invalid (in a way) and because the CodeDOM structure is not quite compatible with F#. If you really need to get this to work, you may have to add similar hacks (by modifying the source from CodePlex)
I tink that a safer approach is to include a small C# library project that generates the reference for you or invoking the C# compiler using csc.exe as Brian suggests.

SvcUtil and 'System.Xml.Linq.XElement' cannot be converted to 'System.Xml.XmlElement' compiler error

I always recieve the above error when I generate a proxy class for my service using SvcUtil. The service is exposing a property that is of System.Xml.Linq.XElement type. The SvcUtil generates a System.Xml.XmlElement type property unfortunately. On the other hand if I'm using Add Reference in VS to generate the proxy class, everything's ok. I tried the latest 4.0 version of SvcUtil from the NETFX 4.0 Tools folder, but still with no luck.
In case anyone is still looking, like I was, the answer is here: http://social.msdn.microsoft.com/Forums/en/wcf/thread/42dbe820-3f59-4662-9664-83999e1746c0
Yaron Naveh suggests adding a /reference argument to SvcUtil.exe.
svcutil /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" http://localhost...