开发者

Auto generate C# interfaces (with function prototypes) from XSD?

开发者 https://www.devze.com 2023-01-30 20:52 出处:网络
I know how to define classes/data-structures in XSD format and auto-generate equivalent C# classes (with either xsd.exe or the more elaborated xsd2code.exe).

I know how to define classes/data-structures in XSD format and auto-generate equivalent C# classes (with either xsd.exe or the more elaborated xsd2code.exe).

I would like to define interface classes with methods that utilize the above defined data-structures. The goal is to create some process-to-process (on the same machine) communication protocol with str开发者_JS百科ong-typed classes and interfaces.

I have a big salad in my head, combined from XSD, WSDL, SOAP, REST and more.. which technology should I use?

10x.


XSD is used to define data types, not interfaces or protocols. I would go for mixing WSDL and XSD. I mean, you create a WSDL that defines interfaces and methods, then bind the arguments for those methods to types defined in an XSD, either internal or external to the WSDL.

Samples here. As you can see, logbus-management.wsdl not only includes an XSD on its own, but also strongly refers the filter namespace from logbus-filters.xsd.

From that WSDL, you can use, in my case wsdl /serverInterfaces logbus-management.wsdl logbus-filters.xsd and get both the C# interfaces and all the data types into one C# source code file. If you also generate a proxy via Visual Studio, you can get your SOAP. You might need a web service (ie. ASP.NET, possibly in serverless mode) but I'm not sure if you can run SOAP with remoting (you should) or use WCF.

Hope I have been of help.

Follow-up

You now need to use Remoting to let process communicate. Here I found a tutorial. Your skeleton code should look like:

using System;
 
namespace addsubs
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class addsubs : MarshalByRefObject, IMultiplier //what you compiled from WSDL
    {
        public int product;
        public int multiply(int a, int b)
        {
            product = a * b;
            return product;
        }
    }
}

Both application must share the IMultiplier interface (or whatever), and then, when you get a reference to your skeleton object (via a local proxy that .NET is supposed to create for you), cast it to IMultiplier

Note to other users

I have no direct experience with .NET Remoting, as I said. Please don't downvote my answer if what I just said is wrong. Instead, please help our friend achieve his goal.

Thank you


Here's the solution I ended up using: http://www.codeproject.com/KB/codegen/XSLCodeGen.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消