【问题标题】:WCF service with multiple service contracts with duplicate method names in single wsdl具有多个服务合同的 WCF 服务,在单个 wsdl 中具有重复的方法名称
【发布时间】:2015-10-28 10:32:16
【问题描述】:

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

[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);
    }
}

由于我无法控制的原因:

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

  • 我需要一个具有多个端点的服务。
  • 我需要像 this 这样的服务(最好在 WCF 上)。

总之,我需要在单个 wsdl 中具有多个具有重复方法名称的服务合同的 WCF 服务。有没有办法实现?

【问题讨论】:

  • 你不能这样做,因为它相当于重载一个方法,并且在wsdl中是不允许的。在此处查看更多信息:stackoverflow.com/questions/10276124/… 和此处:w3.org/TR/2002/WD-wsdl12-20020709
  • @RicardoPontual 如何使用 WCF 获得像 this 这样的 wsdl?在这个 wsdl 中,<portType name="RegistrationSoapPort"><operation name="AcceptRequest" parameterOrder="RequestID"><portType name="CertRequestSoapPort"><operation name="AcceptRequest" parameterOrder="RequestID Request"> 在一个命名空间中。
  • 我作为答案发布,因为评论有点长
  • 您必须在 Web 中配置两个端点。 config,那么它也可以显示SingleWsdl

标签: c# web-services wcf soap wsdl


【解决方案1】:

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

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

wsdl service.wsdl /out:service.cs

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

希望对你有帮助。

【讨论】:

  • 生成的文件包含对service.wsdl 文件中描述的服务的访问描述。但是我需要与service.wsdl描述的服务具有相同接口的服务。
  • 使用 serviceinterface 参数,您将拥有接口而不是类:wsdl service.wsdl /out:service.cs /serverInterface
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2012-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多