Search code examples
c#.netwcfwsdl

Generated wsdl file contains strange message names. WCF


In generated wsdl file (form WCF service) there is a strange name template (maybe only for me). For example section describing a method:

<wsdl:message name="InterfaceName_MethodName_InputMessage">
    <wsdl:part name="parameters" element="tns:MethodName"/>
</wsdl:message>

How can i force WCF not to generate InterfaceName prefix and InputMessage postfix? The same situation is in OutputMessage case. I want wsdl to look as shown below:

<wsdl:message name="MethodName">
    <wsdl:part name="parameters" element="tns:MethodName"/>
</wsdl:message>

Solution

  • You can change the message element with MessageContract.Supposed your method in the interface looks like this:

    <OperationContract>
    Function methodName(param as String) as Integer
    

    Then you must change it to:

    <OperationContract>
         Function methodName(param As messageInput) As mesageOutput
    

    Add these classes:

    <MessageContract()> _
        Public Class messageInput
    
        Private input1 As String
    
        <DataMember(Name:="input")> _
        Public Property input() As String 
            Get
                Return Me. input1
            End Get
            Set(ByVal value As String)
                Me. input1 = value
            End Set
        End Property
    
    End Class
    
    <MessageContract()> _
    Public Class mesageOutput
    
        Private return1 As Integer
    
        <DataMember(Name:="return")> _
        Public Property return() As Integer
            Get
                Return Me. return1
            End Get
            Set(ByVal value As Integer)
                Me. return1 = value
            End Set
        End Property
    
    End Class
    

    Now your message element has change to this:

    <wsdl:operation name="methodName">
        <wsdl:input message="messageInput"/>
        <wsdl:output message="messageOutput"> 
    </wsdl:operation>
    

    Edit1:

    To change the method name and the action Attribute do this in the interface:

    <OperationContractAttribute(Action:="actionName", name:="manipulateMethodName" ReplyAction:="actionResonseName")> _
    Function methodName(param As messageInput) As mesageOutput