C# WCF-使用名称空间对服务进行版本控制时生成平面WSDL时出错

C# WCF-使用名称空间对服务进行版本控制时生成平面WSDL时出错,c#,.net,wcf,wsdl,versioning,C#,.net,Wcf,Wsdl,Versioning,我有一个WCF Web服务,我想将其升级。在本例中,我有一个特定的操作MyOperation,它改变了类型签名,并且在语义上也发生了足够的变化,从而可以获得一个新的主要版本。如果可能的话,我希望客户机只将名称空间从v1更改为v2,并且能够使用新操作 我使用严格的版本控制,并像这样定义服务契约(我使用占位符名称): 我想将MyOtherOperation更改为具有新返回类型的新版本,但其他操作保持不变(如MyOtherOperation) 服务定义如下(使用默认实现): 在我的Web.config

我有一个WCF Web服务,我想将其升级。在本例中,我有一个特定的操作
MyOperation
,它改变了类型签名,并且在语义上也发生了足够的变化,从而可以获得一个新的主要版本。如果可能的话,我希望客户机只将名称空间从v1更改为v2,并且能够使用新操作

我使用严格的版本控制,并像这样定义服务契约(我使用占位符名称):

我想将
MyOtherOperation
更改为具有新返回类型的新版本,但其他操作保持不变(如
MyOtherOperation

服务定义如下(使用默认实现):

在我的Web.config中,我有以下定义:

<behaviors>
    <endpointBehaviors>
        <behavior name="MyEndpointBehavior" />
    </endpointBehaviors>
</behaviors>

<serviceBehaviors>
    <behavior name="MyServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="true" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="Failure" />
        <aspNetCompatibilityRequirementsBehavior requirementsMode="Allowed" />
    </behavior>
</serviceBehaviors>

<bindings>
    <basicHttpBinding>
        <binding name="MyBinding">
            <security mode="None" />
        </binding>
    </basicHttpBinding>
</bindings>

<service behaviorConfiguration="MyServiceBehavior" name="MyCompany.MyService">
    <endpoint address="" behaviorConfiguration="MyEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="MyService" contract="MyCompany.IMyService" />

    <endpoint address="" behaviorConfiguration="MyEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="MyService_v2" contract="MyCompany.IMyService_v2" />
</service>
使用上述解决方案,我的服务的两个版本都托管在。如果客户机想要调用v1,他只需要使用名称空间http://mycompany.com/myService/v1; 如果他想更改为v2版本,他只需要将名称空间更改为。正确生成了包含导入的WSDL文件,但仅错误生成了平面WSDL文件。我需要生成平面WSDL以提供给第三方

是否有可能拥有上述版本控制系统,并且仍然使用?singleWSDL正确生成平面WSDL


如果没有,更好的选择是什么?

WSDL有一个根元素,其属性定义了所描述服务的名称空间,因此不能在一个WSDL中使用两个服务名称空间。也许您可以将得到的WSDL和xsd组合成每个服务的一个WSDL,包含它自己的类型定义?每个主要的(打破的)版本必须在一个新的服务中?考虑第一个?WSDL作为WSDL的全功能方式,根据WCF(严格)版本策略,在单个服务中有更多的合同。如果您想使用此版本控制,这是默认的(通常的)方法。第二个?singleWsdl可以在@CodeCaster已经指出的只有一个根命名空间的情况下使用。或者在版本控制方面使用单一合同。这就是为什么它被称为singleWSDL:)
public class MyService : IMyService, IMyService_v2
{
    public MyOpResponse_v2 MyOperation_v2(string parameter)
    {
        return new MyOpResponse_v2 { Value = parameter.Length };
    }

    public int MyOtherOperation(int parameter)
    {
        return parameter + 100;
    }

    public MyOpResponse MyOperation(string parameter)
    {
        return new MyOpResponse { Value = parameter };
    }
}
<behaviors>
    <endpointBehaviors>
        <behavior name="MyEndpointBehavior" />
    </endpointBehaviors>
</behaviors>

<serviceBehaviors>
    <behavior name="MyServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="true" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="Failure" />
        <aspNetCompatibilityRequirementsBehavior requirementsMode="Allowed" />
    </behavior>
</serviceBehaviors>

<bindings>
    <basicHttpBinding>
        <binding name="MyBinding">
            <security mode="None" />
        </binding>
    </basicHttpBinding>
</bindings>

<service behaviorConfiguration="MyServiceBehavior" name="MyCompany.MyService">
    <endpoint address="" behaviorConfiguration="MyEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="MyService" contract="MyCompany.IMyService" />

    <endpoint address="" behaviorConfiguration="MyEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="MyService_v2" contract="MyCompany.IMyService_v2" />
</service>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:i1="http://mycompany.com/myService/v2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:i0="http://mycompany.com/myService/v1" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" name="MyService" targetNamespace="http://mycompany.com/myService/v2">
    <wsdl:binding name="MyService" type="i0:IMyService">
    ...
    </wsdl:binding>

    <wsdl:binding name="MyService_v2" type="i1:IMyService_v2">
    ...
    </wsdl:binding>

    <wsdl:service name="MyService">
        <wsdl:port name="MyService" binding="tns:MyService">
            <soap:address location="http://localhost/MyService.svc"/>
        </wsdl:port>
        <wsdl:port name="MyService_v2" binding="tns:MyService_v2">
            <soap:address location="http://localhost/MyService.svc"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
System.NotSupportedException: A single WSDL document could not be generated for this service. Multiple service contract namespaces were found (http://mycompany.com/myService/v1, http://mycompany.com/myService/v2). Ensure that all your service contracts have the same namespace.