SvcUtil vs WseWsdl3 - c#

Official VmWare documentation describes how to use WseWsdl3.exe utility to generate csharp file VimService.cs from a set of .wsdl files:
wsewsdl3.exe /n:Vim25Api /type:webClient /l:CS vim.wsdl vimService.wsdl
Since the package Microsoft Web Services Enhancements (WSE) 3.0 for Microsoft .NET is deprecated, what is an alternative to generate the same VimService.cs (supposedly, with the utility SvcUtil.exe)?
The end goal is to create a self-contained script file which could generate final Vim25Service.dll without installing any old and unnecessary packages. The bad thing with WseWsdl3.exe is that it doesn't respect the principle of least privilege, i.e. it looks up the path to a supporting wsdl.exe utility in the system registry, which makes WseWsdl3.exe unportable. Luckily WseWsdl3.exe is a .NET application and I could easily modify it myself, so that it takes the path to wsdl.exe as an argument, but, unfortunately, the license does not allow reverse engineering and especially recompilation of the program.
When I try to use SvcUtil.exe like that:
SvcUtil.exe /language:cs vim.wsdl vimService.wsdl
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: There was a problem loading the XSD documents provided: a reference to a schema type with name 'DestroyPropertyFilterRequestType' and namespace 'urn:vim25' could not be resolved because the type definition could not be found in the schema for targetNamespace 'urn:vim25'. Please check the XSD documents provided and try again.
XPath to Error Source: //wsdl:definitions[#targetNamespace='urn:vim25']/wsdl:portType[#name='VimPortType']

Use wsdl to generate the C# file.
wsdl /n:Vim25Api /o:VimService.cs vim.wsdl vimService.wsdl
https://msdn.microsoft.com/en-us/library/7h3ystb6(v=vs.100).aspx

Related

Generating C# files from Protobuf Definition that imports Google Types using Grpc.Tools [duplicate]

I build an asp net core API project with a docker. This project contains some proto files and imports some google well-known types. But I got output errors:
- google/protobuf/Timestamp.proto : error : File not found. [/src/mymy/mymy.csproj]
- Protos/notification.proto(4,1): error : Import "google/protobuf/Timestamp.proto" was not found or had errors. [/src/mymy/mymy.csproj]
- Protos/notification.proto(112,5): error : "google.protobuf.Timestamp" is not defined. [/src/mymy/mymy.csproj]
I put my source code in github: https://github.com/pearl2201/docker-aspnetcore-grpc
It is correct... they're not defined; with Grpc.Tools, imports still need to exist. You can use the ProtoRoot option on the <Protobuf ...> line to tell it where the root is, for this purpose. In BUILD-INTEGRATION there is also some mention of $(Protobuf_StandardImportsPath), but that seems to refer only to <ProtoCCommand>.
(as an aside: the protobuf-net tools include copies of all the common imports inside the package; if they aren't resolved from the file system, it looks to see what it has inside the assembly instead, but: this is not a direct change, as the protobuf-net tools output very different C#, intended for a different library implementation).

Missing googleapis/google/protobuf

I am attempting to compile a C# library for GoogleCloudSpeechToTextv1p1beta1 from a .proto file here. The protobuf compiler works, except that it is missing dependencies from the googleapis/google/protobuf directory. All of the other import files that it depends on exist, here.
My question is this: Why is the protobuf directory missing from the googleapis/google directory? Is it a library that I need to compile/assemble personally? Or is it something Google should be providing and it's just missing?
The google/protobuf directory is shipped with the Google.Protobuf.Tools package, under tools (so there's tools/google/protobuf/any.proto for example). Alternatively, the same files are within the protobuf GitHub repo (under src - the protos are mixed with the C++ code).
So you should include the tools directory as a "root" in the protoc call if you need to... but in this particular case, there's already a NuGet package of Google.Cloud.Speech.V1P1Beta1 so I'd suggest you use that instead :) (There are even docs available if you know to extrapolate the URL scheme from other APIs. It's not really advertised as such.)

How to generate WCF service with SvcUtil.exe

I am using SvcUtil.exe to generate IClassName.cs file from wsdl file and that is working fine. My problem is that I do not know how to generate ClassName.svc file using command arguments for SvcUtil.exe.
After running the SvcUtil.exe I would like to get WCF service like when you created from Visual Studio Wizard containing all classes *.svc, *.cs, and interface.
Thank You,
Skrch
First of all to generate proxy class we need to have our service up and running. So before using this utility make sure that your service is running without any issue.
After verifying the service status go to Visual Studio Command Prompt and run the following command.
svcutil http://localhost/MyService/ClassName.svc /Language=c#
/t:Code /out:ClassNameProxy.cs /config:ClassNameProxy.config
In above command you should replace the service URL ( http://localhost/MyService/Service1.svc) with the URL of your service.
Since my services is developed in c#.net so I choose to generate the proxies in the same language by using /Language=c# flag.
/t:code will specify that the out put should be generated as code.
/out:ClassNameProxy.cs /config:ClassNameProxy.config parameters will tell the utility to name the files as specified in these parameter values.
After you run the command, tool will generate the output file and config file.
After that just include the ClassNameProxy.cs file into your project and open the ClassNameProxy.config file and copy the entries to your web.config file.
You may also need to update the ClassNameProxy.vb file and update the namespace as per the one that you are using in your project. After that you can easily reference the service in your code and call the operations.
Some examples from tool how it can be used
svcutil http://service/metadataEndpoint
- Generate client code from a running service or online metadata documents.
svcutil *.wsdl *.xsd /language:C#
- Generate client code from local metadata documents.
svcutil /dconly *.xsd /language:VB
- Generate Data Contract types in VisualBasic from local schema documents.
svcutil /t:metadata http://service/metadataEndpoint
- Download metadata documents from running services
svcutil myAssembly.dll
- Generate metadata documents for Service Contracts and associated types in
an assembly
svcutil myServiceHost.exe /serviceName:myServiceName
- Generate metadata documents for a service, and all associated Service
Contracts and data types in an assembly
svcutil myServiceHost.exe /dconly
- Generate metadata documents for data types in an assembly
svcutil /validate /serviceName:myServiceName myServiceHost.exe
- Verify service hosting
svcutil /t:xmlserializer myContractLibrary.exe
- Generate serialization types for XmlSerializer types used by any Service
Contracts in the assembly
For anyone still looking for the answer and could not get the 2012 version working, Visual Studio 2015 and .Net 4.5 have updated the svcutil.exe tool to use /serviceContract switch to generate a class that can then be implemented as a .svc service.
You may need to provide /syncOnly /wrapped /messageContract switches as well depending on the original XSD's
Svcutil.exe generates the service client proxy based on the Web Service Description Language (WSDL) from the service.
Open the visual studio command prompt and run the command
svcutil http://localhost/MyService/Service.svc /Language=c# /t:Code /out:C:\Service\ServiceProxy.cs /config:C:\Service\ServiceProxy.config
it generates two files in C:\Service folder, the proxy file and config file,
More details here.
I think the .NET 4.5 Contract First Tool, integrated into Visual Studio 2012 as a build task, will help you generate the service files you need.
Service contracts often need to be created from existing services. In .NET Framework 4.5, data contract classes can be created automatically from existing services using the contract-first tool. To use the contract-first tool, the XML schema definition file (XSD) must be downloaded locally; the tool cannot import remote data contracts via HTTP.
http://msdn.microsoft.com/en-us/library/hh674270(v=vs.110).aspx

What is IDR_TYPELIB1?

I can't find any good resources online about what this is. It's required in one of the steps for deploying a .NET assembly for use by COM, but there is no detail what it is or what it means.
As an example, here is something from the book I'm reading on Interop:
Next you need to create a resource script MyExampleAssembly.res with the following statement:
(This gets run at the VS command prompt in the directory where you just exported your .NET component using the Type Library Exporter Utility)
IDR_TYPELIB1 typelib "MyExampleAssembly.tlb"
What is IDR_TYPELIB1?
Also, it's not working for me. I have tried running this and it doesn't compile. I get a message "'IDR_TYPELIB1' is not recognized as an internal or external command".
It is a macro that's normally auto-generated when you use the unmanaged resource editor. Just use a constant, 1 is fine. You are also using the wrong tool to compile the resource script by the sound of it, you must run rc.exe. It translates your .rc file to a .res file that the C# compiler can use.
Embedding the type library is optional btw, it is not something that COM Automation requires. It is not a very good idea to do this in a managed project since the .tlb is generated after building the project. Instead of before, as happens in a native COM project. You create it with regasm.exe, /tlb option or the tlbexp.exe utility. Your client can do this too.

Convert Interface IDL file to C#

I have an interface defined in an IDL file that I would like to use in C#. Is there a way to convert the IDL to something usable in C#?
One way is to run MIDL on the IDL to create a type library (.tlb). This requires a library block in the IDL. Once you have the .tlb, you can run tlbimp.exe on it to get a C# definition/Interop DLL.
What datatypes/structures are used in the IDL? You should first define the datatypes in C# first if there is no inbuild type already.
You can use the following tool to convert the structures, but you need to verify the ouput manually.
Download: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe
This utility is described at Accessing Windows API Constants and Structs for P/Invoke.
The original January 2008 article is now only available as a .CHM help file download, linked at the bottom of https://msdn.microsoft.com/magazine/msdn-magazine-issues. For the time being, the source code can be found at http://clrinterop.codeplex.com/.
For example, I've recently used the XPS Print API and needed the xpsobjectmodel.h interfaces. The Windows SDK comes with xpsobjectmodel.idl fortunately.
I generated the TLB file with MIDL first and used TLBIMP to generate a proper DLL assembly ready to be added in the 'References...' section in my C# project.
Be sure to use the tools with the correct version for your project framework. e.g, if your project framework is 3.5-based, using tlbimp from the 4.0 toolset won't work.

Categories