问题
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