我试图使用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;
}
}
}
有人可以帮忙吗?
答案 0 :(得分:2)
记录SoapRequest尝试MessageInspector或启用Web.Config for Web Service登录。
答案 1 :(得分:0)
通常,您不必像这样序列化我们的对象。 您应该通过WSDL-url添加Web-Reference,并通过生成的代理类调用服务的方法