创建肥皂请求

发布于 2024-11-09 01:13:22 字数 2145 浏览 0 评论 0原文

我尝试使用 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;
        }
    }
}

有人可以帮忙吗?

I've tried to serialize an object with XmlSerializer and SoapFormatter but i can't get the output to look like this:

<?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>

My classes:

[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;
        }
    }
}

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放血 2024-11-16 01:13:22

要记录 SoapRequest,请尝试 MessageInspector 或在 Web.Config 中启用 Web 服务的日志记录。

To Log the SoapRequest try MessageInspector or enable the Logging in Web.Config for Web Service.

╰沐子 2024-11-16 01:13:22

一般来说,您不必像这样序列化我们的对象。
您应该通过 WSDL-url 添加 Web-Reference,并通过生成的代理类调用服务的方法

Generally, you do not have to serialize our objects way like that.
You should add the Web-Reference via WSDL-url, and invoke methods of the service by the generated proxy class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文