具有多个服务契约的 WCF 服务,在单个 wsdl 中具有重复的方法名称 [英] WCF service with multiple service contracts with duplicate method names in single wsdl

查看:26
本文介绍了具有多个服务契约的 WCF 服务,在单个 wsdl 中具有重复的方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续这个这个问题.我有两个使用相同方法的服务合同:

Continuing this and this questions. I have two service contract with the same methods:

[ServiceContract]
public interface IServices1
{
    [OperationContract]
    string GetData(int value);
}

[ServiceContract]
public interface IServices2
{
    [OperationContract]
    string GetData(int value);
}

和服务:

public class Service : IServices1, IServices2
{
    string IServices1.GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }

    string IServices2.GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }
}

根据我无法控制的原因:

According to reasons beyond my control:

  • this answer not for me, I need to keep the original names.
  • this answer not for me, I need single wsdl file. If you use a different namespaces, when you try to open single wsdl from service main page (http://addresToService/Service.svc?singleWsdl) get the error:

System.NotSupportedException:无法为此服务生成单个 WSDL 文档.找到了多个服务合同命名空间(IServices1、IServices2).确保您的所有服务合同都具有相同的命名空间.

System.NotSupportedException: A single WSDL document could not be generated for this service. Multiple service contract namespaces were found (IServices1, IServices2). Ensure that all your service contracts have the same namespace.

  • 我需要具有多个端点的一项服务.
  • 我需要像 this 这样的服务(最好在 WCF 上).
    • I need one service with several endpoints.
    • I need service like this (preferably on WCF).
    • 总而言之,我需要具有多个服务合同的 WCF 服务,并且在单个 wsdl 中具有重复的方法名称.有没有办法实现它?

      Summarizing, I need WCF service with multiple service contracts with duplicate method names in single wsdl. Is there a way to achieve it?

      推荐答案

      从 wsdl 文件生成您的类.将 http://pastebin.com/277DFF7H 的内容保存在一个文件中,例如service.wsdl".不要忘记 <?xml version="1.0" encoding="UTF-8"?> 标签必须首先像第一列.

      Generate your classes from the wsdl file. Save the content of http://pastebin.com/277DFF7H in a file, like "service.wsdl". Don't forget that <?xml version="1.0" encoding="UTF-8"?> tag must be at first like, first column.

      然后从 Developer Command Prompt 运行 wsdl.exe 实用程序,如下所示:

      Then run the wsdl.exe util from Developer Command Prompt , like this:

      wsdl service.wsdl /out:service.cs
      

      现在您拥有 wsdl 所需的合同,您可以进行任何需要的更改.

      Now you have the contracts as wsdl requires, and you can do any changes you need.

      希望有帮助.

      这篇关于具有多个服务契约的 WCF 服务,在单个 wsdl 中具有重复的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆