How to change WebService's response's tag name in .NET/ASMX?
I have the following code:
namespace WebService1
{
[System.Web.Services.WebService(Namespace = "mynamespace",
Name = "ControlModuleService")]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Services.WebServiceBindingAttribute(Name = "ControlModulePort"),
SoapDocumentService(SoapBindingUse.Literal,SoapParameterStyle.Bare)]
public class Service1 : CommandCenter
{
[WebMethod, SoapDocumentMethod(
ResponseElementName = "setConfigurationResponse")]
public setConfigurationResponse setConfiguration(setConfigurationRequest request)
{
return new setConfigurationResponse();
}
}
The type:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName = "setConfigurationResponse", WrapperNamespace = "mynamespace", IsWrapped = false)]
public partial class setConfigurationResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "mynamespace", Order = 0)]
[System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public transaction[] @return;
public setConfigurationResponse()
{
}
public setConfigurationResponse(transaction[] @return)
{
this.@return = @return;
}
}
It generates the following WSDL:
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="mynamespace">
<s:element name="request" type="tns:setConfigurationRequest" />
<s:complexType name="setConfigurationRequest">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="transactions" type="tns:transaction" />
<s:element minOccurs="1" maxOccurs="1" form="unqualified" name="turnOnMode" type="s:boolean" />
<s:element minOccurs="1" maxOccurs="1" form="unqualified" name="turnOffMode" type="s:boolean" />
</s:sequence>
</s:complexType>
<s:complexType name="transaction">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" form="unqualified" name="idCC" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" form="unqualified" name="idTrans" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" form="unqualified" name="startTime" type="s:long" />
<s:element minOc开发者_StackOverflowcurs="1" maxOccurs="1" form="unqualified" name="state" type="s:int" />
</s:sequence>
</s:complexType>
<s:element name="setConfigurationResult" type="tns:setConfigurationResponse" />
<s:complexType name="setConfigurationResponse">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="return" type="tns:transaction" />
</s:sequence>
</s:complexType>
...
</s:schema>
</wsdl:types>
Why is it changing the name setConfigurationResponse to setconfigurationResult? How can I change it?
It was as simple as it was complex and obscure to find:
Right above the definition of the class:
[XmlRoot(DataType = "setConfigurationResponse", ElementName = "setConfigurationResponse")]
Resulting in...
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName = "setConfigurationResponse", WrapperNamespace = "mynamespace", IsWrapped = false)]
[XmlRoot(DataType = "setConfigurationResponse", ElementName = "setConfigurationResponse")]
public partial class setConfigurationResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "mynamespace", Order = 0)]
[System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public transaction[] @return;
public setConfigurationResponse()
{
}
public setConfigurationResponse(transaction[] @return)
{
this.@return = @return;
}
}
and finally... :)
<s:element name="setConfigurationResponse" nillable="true" type="tns:setConfigurationResponse"/>
−
<s:complexType name="setConfigurationResponse">
−
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="return" type="tns:transaction"/>
</s:sequence>
</s:complexType>
[XmlRoot(DataType = "setConfigurationResponse", ElementName = "setConfigurationResponse")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName = "setConfigurationResponse", WrapperNamespace = "mynamespace", IsWrapped = false)]
[XmlRoot(DataType = "setConfigurationResponse", ElementName = "setConfigurationResponse")]
public partial class setConfigurationResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "mynamespace", Order = 0)]
[System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public transaction[] @return;
public setConfigurationResponse()
{
}
public setConfigurationResponse(transaction[] @return)
{
this.@return = @return;
}
}
精彩评论