生成的wsdl文件包含奇怪的消息名称。 WCF

时间:2015-09-24 12:19:10

标签: c# .net wcf wsdl

在生成的wsdl文件(表单WCF服务)中,有一个奇怪的名称模板(可能仅适用于我)。例如,描述方法的部分:

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

如何强制WCF不生成 InterfaceName 前缀和 InputMessage 后缀?同样的情况出现在 OutputMessage 的情况中。我希望wsdl看起来如下所示:

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

1 个答案:

答案 0 :(得分:1)

您可以使用MessageContract更改消息元素。假设您在接口中的方法如下所示:

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

然后您必须将其更改为:

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

添加这些类:

<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

现在您的消息元素已更改为:

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

<强> EDIT1:

要更改方法名称和操作属性,请在界面中执行以下操作:

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