none
Multiple types in WSDL definitions RRS feed

  • Question

  • Hi,

    I need to be able to have different types in the WSDL definitions for a WCF service like this:

    <?xml version="1.0" encoding="utf-8"?>
    <wsdl:definitions xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:s2="http://example.com/Operation2"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:tns="http://example.com"
    xmlns:s1="http://example.com/Operation1"
    xmlns:s0="http://example.com/Operation0"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    targetNamespace="http://example.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    	<wsdl:types>
    		<xs:schema elementFormDefault="qualified" targetNamespace="http://example.com/Operation0">
    			<xs:element name="Operation0">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Input" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation0Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Operation0Result" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    		</xs:schema>
    		<xs:schema elementFormDefault="qualified" targetNamespace="http://example.com/Operation1">
    			<xs:element name="Operation1">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Input" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation1Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Operation1Result" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    		</xs:schema>
    		<xs:schema elementFormDefault="qualified" targetNamespace="http://example.com/Operation2">
    			<xs:element name="Operation2">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Input" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation2Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" maxOccurs="1" name="Operation2Result" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    		</xs:schema>
    	</wsdl:types>


    So far with a simple WCF service definition:

    [ServiceContract(Name="MyService", Namespace = "http://example.com")]
    public interface MyServiceI
    {
        [OperationContract(Action = "http://example.com/Operation0")]
        [return: MessageParameter(Name = "Operation0Result")]
        string Operation0(string Input);
    
        [OperationContract(Action = "http://example.com/Operation1")]
        [return: MessageParameter(Name = "Operation1Result")]
        string Operation1(string Input);
    
        [OperationContract(Action = "http://example.com/Operation2")]
        [return: MessageParameter(Name = "Operation2Result")]
        string Operation2(string Input);
    }

    I get this:

    <?xml version="1.0" encoding="utf-8"?>
    <wsdl:definitions name="MyService" targetNamespace="http://example.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
    xmlns:wsa10="http://www.w3.org/2005/08/addressing"
    xmlns:tns="http://example.com"
    xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<wsdl:types>
    		<xs:schema elementFormDefault="qualified" targetNamespace="http://example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    			<xs:element name="Operation0">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Input" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation0Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Output" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation1">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Input" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation1Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Output" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation2">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Input" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    			<xs:element name="Operation2Response">
    				<xs:complexType>
    					<xs:sequence>
    						<xs:element minOccurs="0" name="Output" nillable="true" type="xs:string"/>
    					</xs:sequence>
    				</xs:complexType>
    			</xs:element>
    		</xs:schema>

    How can I have the different OperationContracts get separated in the WSDL?

    Thank you in advance.

    Regards,

    Elder

    Sunday, December 1, 2019 11:08 PM

All replies

  • Hi,

    Based on the article Multiple Service Contract in WCF on CodeProject, I thought on using different service contracts with different namespaces but regretfully, I got an error while trying to check the WSDL.

    Might this be the route to follow?

    [ServiceContract(Namespace="Test1")]
    public interface IMultiplePublicService
    {
    	[OperationContract]
    	string GetPublicInformation();
    }
    
    [ServiceContract(Namespace = "Test2")]
    public interface IMultipleConfidentialService
    {
    	[OperationContract]
    	string GetConfidentialInformation();
    } 


    public class MultipleService : IMultiplePublicService, IMultipleConfidentialService   
    {   
        public string GetPublicInformation()   
        {   
            return "I am watching Public Information over HTTP.";   
        }   
       
        public string GetConfidentialInformation()   
        {   
            return "I am watching Confidential Information over TCP.";   
        }   
    } 

    The error explicitly tells that there are two namespaces

    An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
    System.NotSupportedException: A single WSDL document could not be generated for this service. Multiple service contract namespaces were found (Test1, Test2). Ensure that all your service contracts have the same namespace.

    Might .Net WCF be unable to have different types?




    • Edited by Elder Pérez Tuesday, December 3, 2019 4:36 PM Cannot add links
    Tuesday, December 3, 2019 4:32 PM