2010-11-25 68 views
5

我有以下代碼:如何在.NET/ASMX中更改WebService的響應標記名稱?

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(); 
     } 
} 

類型:

[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) 
     { 
      [email protected] = @return; 
     } 
    } 

生成下面的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 minOccurs="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> 

爲什麼更改名稱setConfigurationResponse到setconfigurationResult? 我該如何改變它?

回答

6

很簡單,因爲它是複雜的,晦澀地發現:

權的類定義的上方:

[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) 
     { 
      [email protected] = @return; 
     } 
    } 

,並最終導致... :)

<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> 
+0

將此貼標爲答案! – decyclone 2010-11-25 11:32:42

1
[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) 
     { 
      [email protected] = @return; 
     } 
    } 
相關問題