xmlwcfsoapnamespacesoperationcontract

Change Prefix To DataContract Inherited From OperationContract Namespaces


Please I need change the FORMULARIO'S Prefix (Tem: TO Men1:) from this XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:men="http://Mensajes.General.inHeader" xmlns:tem="http://tempuri.org/" xmlns:men1="http://Mensajes.Formularios.Guardar">
   <soapenv:Header>
      <men:inHeader>
         <DSUSUARIO></DSUSUARIO>
         <PWDUSUARIO></PWDUSUARIO>
      </men:inHeader>
   </soapenv:Header>
   <soapenv:Body>
      <tem:Guardar> <!--OperationContract-->
         <tem:FORMULARIO> <!--DataContract-->
         </tem:FORMULARIO>
      </tem:Guardar>
   </soapenv:Body>
</soapenv:Envelope>

The problem is that i can't set a Namespace to OperationContract to override the Namespace Base. In this chase the OperationContract is the parent from DataContract at Xml.

My code is:

[ServiceContract(Namespace = "http://tempuri.org/")]
public interface IComportamiento
{
[OperationContract]
[XmlSerializerFormat]
Resultado Guardar(FORMULARIO FORMULARIO);
}

public class Implementacion : IComportamiento
{
public Resultado Guardar(FORMULARIO FORMULARIO)
{
...
}
}

[DataContract]
public class FORMULARIO
{
}


Solution

  • MessageContract could change the Root element's namespace but it will remove operationcontract's element , also the return type should also be changed to FORMULARIO.

    [ServiceContract(Namespace = "http://tempuri.org/")]
    
    public interface IComportamiento
    {
        [OperationContract]
    
        FORMULARIO Guardar(FORMULARIO FORMULARIO);
    }
    
    [MessageContract(IsWrapped = true, WrapperName = "FORMULARIO", WrapperNamespace = "http://Mensajes.Formularios.Guardar")]
    public class FORMULARIO
    {
    
    }
    

    The result. enter image description here