Как сериализовать кастомный SOAP для OTRS

124
09 декабря 2019, 10:00

есть WSDL схема для SOAP в OTRS, к сожалению автоматом (подключением ссылок), не получается, потому как шарп считает файл не корректным. для нормальной работы необходимо получить следующее:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="http://www.otrs.org/TicketConnector/">
     <soapenv:Header/>
      <soapenv:Body>
      <SessionCreate>         
              <tic:UserLogin>ULogin</tic:UserLogin>         
              <tic:CustomerUserLogin>CustUser</tic:CustomerUserLogin>         
              <tic:Password>ULPassword</tic:Password>
      </SessionCreate>
   </soapenv:Body>
</soapenv:Envelope>

попробовал через System.Runtime.Serialization.Formatters.Soap следующим образом:

  [Serializable]
public partial class Envelope
{
    /// <remarks/>
    public object Header { get; set; }
    /// <remarks/>
    public EnvelopeBody Body { get; set; }
}
 [Serializable]
public partial class EnvelopeBody
{     
   public SessionCreate SessionCreate { get; set; }
}
[Serializable]
[System.Xml.Serialization.SoapType(IncludeInSchema =true, Namespace = "")]
public partial class SessionCreate
{
    /// <remarks/>
    [System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
    public string UserLogin { get; set; }
    /// <remarks/>
    [System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
    public string CustomerUserLogin { get; set; }
    /// <remarks/>
    [System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
    public string Password { get; set; }
}
class TEST
{
  void GetSoap()
  {
     var model = new SessionCreate
        {
            UserLogin ="ULogin",
            CustomerUserLogin="CustUser",
            Password="ULPassword"
        };
        var en = new Envelope
        {
            Body = new EnvelopeBody
            {
                SessionCreate = model
            }
        };
         SoapFormatter formatter = new SoapFormatter();
        var ms = new MemoryStream();
        formatter.Serialize(ms, en);
        Console.WriteLine(StreamToString(ms));
  }
  string StreamToString(Stream stream)
    {
        stream.Position = 0;
        using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
        {
            return reader.ReadToEnd();
        }
    }
}

В результате выводит следующее:

 <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <SOAP-ENV:Body>
 <a1:Envelope id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
 <_x003C_Header_x003E_k__BackingField xsi:type="xsd:anyType" xsi:null="1"/>
 <_x003C_Body_x003E_k__BackingField href="#ref-3"/>
 </a1:Envelope>
 <a1:EnvelopeBody id="ref-3" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
 <_x003C_SessionCreate_x003E_k__BackingField href="#ref-4"/>
 </a1:EnvelopeBody>
 <a1:SessionCreate id="ref-4" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
 <_x003C_UserLogin_x003E_k__BackingField id="ref-5">ULogin</_x003C_UserLogin_x003E_k__BackingField>
 <_x003C_CustomerUserLogin_x003E_k__BackingField id="ref-6">CustUser</_x003C_CustomerUserLogin_x003E_k__BackingField>
 <_x003C_Password_x003E_k__BackingField id="ref-7">ULPassword</_x003C_Password_x003E_k__BackingField>
 </a1:SessionCreate>
 </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

Возникает вопрос, как это сделать нормально, и что я делаю не так?

READ ALSO
JavaScript. Создание файла

JavaScript. Создание файла

Всем приветПишу на Vue

108
Ошибка конвертации при запросе insert

Ошибка конвертации при запросе insert

Есть таблица с данными, хочу туда добавить новую строкуНо дословно возникает такая ошибка

108
WebClient .com и .ru

WebClient .com и .ru

При запуске приложения, срабатывает апдейтерПодключение идет через WebClient

103