# Sessao

## Obtendo uma sessão

Para obter uma sessão no DSG, basta fazer uma chamada para método ObterSessao do endpoint DSG.Servicos.Sessao.SVC:

```markup
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:dsg="http://schemas.datacontract.org/2004/07/DSG.Dominio" xmlns:dsg1="http://schemas.datacontract.org/2004/07/DSG.Comandos.Sessao.Obter">
   <soap:Header/>
   <soap:Body>
      <tem:ObterSessao>
         <!--Optional:-->
         <tem:request>
            <dsg1:Senha>SUASENHADODSG</dsg1:Senha>
            <!--Optional:-->
            <dsg1:Usuario>SEUUSUARIODSG</dsg1:Usuario>
         </tem:request>
      </tem:ObterSessao>
   </soap:Body>
</soap:Envelope>
```

{% hint style="info" %}
&#x20;Sessões são objetos que controlam os parâmetros de conexão com os fornecedores, e são imutáveis uma vez criados.

Por isso, você sempre deve reaproveitar as sessões, evitando abrir uma a cada requisição.
{% endhint %}

Se a abertura de sessão for feita com sucesso, você receberá um identificador, que deve ser utilizado em todas as chamadas ao DSG;

```markup
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://tempuri.org/ISessao/ObterSessaoResponse</a:Action>
   </s:Header>
   <s:Body>
      <ObterSessaoResponse xmlns="http://tempuri.org/">
         <ObterSessaoResult xmlns:b="http://schemas.datacontract.org/2004/07/DSG.Comandos.Sessao.Obter" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <Erro xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">false</Erro>
            <IdExecucao xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">5d95be69-5db4-48d5-a511-cc0b3556d966</IdExecucao>
            <LogDeRetorno i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
            <Mensagem i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio"/>
            <TempoExecucao xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">PT0.0289815S</TempoExecucao>
            <TimeStamp xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">2021-08-29T09:16:17.9466312-03:00</TimeStamp>
            <Version xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">3.23.21237.1</Version>
            <WorkUnit xmlns="http://schemas.datacontract.org/2004/07/DSG.Dominio">HML-ZUPPER-DSG_1ff8aa42-f7e4-4205-8f00-1ce50c8ba937</WorkUnit>
            <b:GuidSessao>2a43df6a-ce9b-4746-8d08-1ceb627a43a4</b:GuidSessao>
         </ObterSessaoResult>
      </ObterSessaoResponse>
   </s:Body>
</s:Envelope>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dsg.dnitservices.com/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
