How to put 'Ws:' only in the first xml node of a WCF service request?

Asked

Viewed 50 times

0

I have a WCF application that has a vehicle.svc service as in figure 1. inserir a descrição da imagem aqui

In the vehicle service.svc has a recording method that receives a vehicle DTO as in figure 2.

inserir a descrição da imagem aqui

public class VeiculoDto
{
    public string AnoFabricacao { get; set; }
    public string AnoModelo { get; set; }
    public string Placa { get; set; }
}

In turn the service Veiculo.svc implements the interface Iveiculo.Cs that has a record contract as in figure 3.

inserir a descrição da imagem aqui

Using Soapui to make a call in this service I have the following request:

inserir a descrição da imagem aqui

The request must have the following structure:

<soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ws="ws">
 <soapenv:Header/>
 <soapenv:Body>
     <ws:Registar>
         <!--Optional:-->
         <veiculo>
             <!--Optional:-->
             <wcf:AnoFabricacao>?</wcf:AnoFabricacao>
             <!--Optional:-->
             <wcf:AnoModelo>?</wcf:AnoModelo>
             <!--Optional:-->
             <wcf:Placa>?</wcf:Placa>
         </veiculo>
     </ws:Registar>
 </soapenv:Body>
</soapenv:Envelope>

I would like to know how to get only the node < Register > to 'Ws:' < Ws:Register > in your tag?

  • The solution solved your problem? or was missing something?

1 answer

2

I wonder how I do so that only the knot <Registar> stay with 'Ws:' <ws:Registar> on your tag?

Yes, you can define that your DTO does not have a namespace. Through the properties of the attribute DataContract.

Take an example:

[DataContract(Namespace = "")]
public class VeiculoDto
{
    [DataMember]
    public string AnoFabricacao { get; set; }
    [DataMember]
    public string AnoModelo { get; set; }
    [DataMember]
    public string Placa { get; set; }
}

In doing so, the result will be as follows in SoapUI:

Resultado no SoapUI

You can also remove the namespace of the service by changing the properties of the attribute ServiceContract.

Example:

[ServiceContract(Namespace ="")]
public class Service
{
}

Uniting the two functionalities, the result is the following:

inserir a descrição da imagem aqui

  • Thank you very much, dear Runo, for your help! However when I use Ws on [Datacontract(Namespace = "Ws")], I don’t know why all child nodes also get Ws on their tag, raw request. I would like it to be just the < register > tag < Ws: register>.

  • I will supplement the answer

  • Dear Thank you very much for the complement! However I performed the test as answered and still inheriting the Ws to <Ws: vehicle>.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.