wsdl.exe:在操作中具有相同元素名称时如何生成代理代码?

发布于 2024-09-25 15:07:56 字数 364 浏览 0 评论 0原文

我有一个包含许多操作的 WSDL 文件。但每个操作soap主体都有相同的元素名称,但位于不同的命名空间中。例如操作1有soap.body.op1:Service 操作2有soap.body.op2:Service,其中op1和op2是命名空间前缀。

当我使用 wsdl.exe 生成代理代码时,他生成了 Service1 和 Service2 类,但是如果在 wsdl 中服务 1 和 2 的顺序发生更改,或者添加了新的服务 3 ,则维护代理代码将变得困难。

有没有办法根据wsdl操作生成Service1和Service2类名,而不是标签名?

所以我会得到类名称为Operation1和Operation2,而不是Service1和Service2。? 谢谢大家。

I have a single WSDL file with many operation. But each of the operation soap body has the same element name , but in different namespaces. e.g operation1 has soap.body.op1:Service
and operation 2 has soap.body.op2:Service , where op1 and op2 are namespace prefixes.

When i generate my proxy code using wsdl.exe , he generated classes as Service1 and Service2, but if the order is changed in wsdl for service 1 and 2 , or if a new service 3 is added, it becomes difficult to maintain the proxy code.

Is there a way to generate the Service1 and Service2 class names based on the wsdl operation , instead of the tag name?

So i would get class names as Operation1 and Operation2 , instead of Service1 and Service2.?
Thanks all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2024-10-02 15:07:56

恐怕 wsdl.exe 没有用于调整它从 WSDL 文档生成的源代码的开关。

使其更易于维护的唯一方法是获得质量更高的 WDSL 文档。如果您可以更改此设置,则可以添加自定义 命名空间名称到通过向 ServiceContract 属性添加更多信息来更改您的服务类:

namespace op1
{
    [ServiceContract(Name = "MyNicelyNamedService", Namespace = "http://mydomain.com/op1")]
    public class Service
    {
        [OperationContract(Name = "MyAwesomeMethod")]
        public void SomeMethod()
        {
            ...
        }
    }
}

这将生成如下客户端代码:

MyNicelyNamedServiceClient client = new MyNicelyNamedServiceClient();
client.MyAwesomeMethod();
client.Close();

I'm afraid that wsdl.exe has no switches for tweaking the source code that it generates from a WSDL document.

The only way to make it more maintainable is to get a better quality WDSL document. If you are in a position to change this, you can add custom Namespace and Name to your service class by adding more information to the ServiceContract attribute:

namespace op1
{
    [ServiceContract(Name = "MyNicelyNamedService", Namespace = "http://mydomain.com/op1")]
    public class Service
    {
        [OperationContract(Name = "MyAwesomeMethod")]
        public void SomeMethod()
        {
            ...
        }
    }
}

This will generate client code like:

MyNicelyNamedServiceClient client = new MyNicelyNamedServiceClient();
client.MyAwesomeMethod();
client.Close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文