Создать запрос soap

#c# #serialization #soap

#c# #сериализация #soap

Вопрос:

Я пытался сериализовать объект с помощью XmlSerializer и SoapFormatter, но я не могу получить вывод, который выглядел бы следующим образом:

 <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Login xmlns="http://www.myfirm.com/2010/core/ConnectTypes">
  <UserLogin>
    <UserName>User</UserName>
    <Password>PW</Password>
    <Mandant>1</Mandant>
  </UserLogin>
</Login>

 </soap:Body>
</soap:Envelope>
  

Мои классы:

 [System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class UserLoginType
{

    private string userNameField;

    private string passwordField;

    private int mandantField;

    /// <remarks/>
    public string UserName
    {
        get
        {
            return this.userNameField;
        }
        set
        {
            this.userNameField = value;
        }
    }

    /// <remarks/>
    public string Password
    {
        get
        {
            return this.passwordField;
        }
        set
        {
            this.passwordField = value;
        }
    }

    /// <remarks/>
    public int Mandant
    {
        get
        {
            return this.mandantField;
        }
        set
        {
            this.mandantField = value;
        }
    }
}

[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class LoginType
{

    private object itemField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("LoginToken", typeof(string))]
    [System.Xml.Serialization.XmlElementAttribute("UserLogin", typeof(UserLoginType))]
    public object Item
    {
        get
        {
            return this.itemField;
        }
        set
        {
            this.itemField = value;
        }
    }
}
  

Кто-нибудь может помочь?

Ответ №1:

Чтобы зарегистрировать SoapRequest, попробуйте MessageInspector или включите ведение журнала в Web.Config для веб-службы.

Комментарии:

1. Для чего мне нужно регистрировать запрос soap?!?

Ответ №2:

Как правило, вам не обязательно сериализовывать наши объекты подобным образом. Вы должны добавить веб-ссылку через WSDL-url и вызвать методы сервиса с помощью сгенерированного прокси-класса

Комментарии:

1. К сожалению, нет файла WSDL.