Changing wsdl:part name

霸气de小男生 提交于 2021-02-10 11:02:01

问题


Is there any way of changing the name of a message part in the WSDL? I have this on my WSDL:

<wsdl:message name="getDataRequestMsg">
    <wsdl:part name="getData" element="tns:getData"/>
</wsdl:message>
<wsdl:message name="getDataRequestMsg_Headers">
    <wsdl:part name="Header" element="tns:Header"/>
</wsdl:message>
<wsdl:message name="getDataResponseMsg">
    <wsdl:part name="getDataResponse" element="tns:getDataResponse"/>
</wsdl:message>
<wsdl:message name="getDataResponseMsg_Headers">
    <wsdl:part name="Header" element="tns:Header"/>
</wsdl:message>

I'm using a MessageContractAttribute and I can actually change the name using the respetive name attribute on the MessageBodyMemberAttribute, but it also changes the element name and that's not what I intended. My MessageContract is as follows:

[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class getDataRequestMsg
{
    [System.ServiceModel.MessageHeaderAttribute()]
    public Header[] Header;

    [System.ServiceModel.MessageBodyMemberAttribute()]
    public getData getData;

    public getDataRequestMsg()
    {
    }

    public getDataRequestMsg(Header[] Header, getData getData)
    {
        this.Header = Header;
        this.getData = getData;
    }
}

[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class getDataResponseMsg
{
    [System.ServiceModel.MessageHeaderAttribute()]
    public Header[] Header;

    [System.ServiceModel.MessageBodyMemberAttribute()]
    public getDataResponse getDataResponse;

    public getDataResponseMsg()
    {
    }

    public getDataResponseMsg(Header[] Header, getDataResponse getDataResponse)
    {
        this.Header = Header;
        this.getDataResponse = getDataResponse;
    }
}

回答1:


[WebMethod()]
[return: System.Xml.Serialization.XmlElement("your_element_name")]
public your_type YourMethod()
{
    // your code
}


来源:https://stackoverflow.com/questions/48099348/changing-wsdlpart-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!