这应该是直截了当的,但经过大量的论坛浏览,我仍然没有找到解决方案。这是:
我有一个相当简单的接口定义如下:
[ServiceContract(Namespace = "test-contract")]
public interface IDebitor : Source.BaseInterface.IBase
{
[OperationContract]
DebitorResult CreateUpdateDebitorPerson(DebitorPerson person)
}
[DataContract(Namespace = "test-person")]
public class DebitorPerson
{
#region FIELDS
// Line
string senderSystemId;
string firstName;
string lastName;
string address1;
string address2;
string postalCode;
string city;
string areaCode;
string cprNumber;
string payingCustomerId;
string paymentCode;
string languageCode;
#endregion
#region Propperties
[DataMember(IsRequired = true, Order = 1)]
public string SenderSystemId
{
get { return senderSystemId; }
set { senderSystemId = value; }
}
[DataMember(IsRequired = true)]
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
[DataMember(IsRequired = true)]
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
[DataMember(IsRequired = true)]
public string Address1
{
get { return address1; }
set { address1 = value; }
}
[DataMember(IsRequired = false)]
public string Address2
{
get { return address2; }
set { address2 = value; }
}
[DataMember(IsRequired = true)]
public string PostalCode
{
get { return postalCode; }
set { postalCode = value; }
}
[DataMember(IsRequired = true)]
public string City
{
get { return city; }
set { city = value; }
}
[DataMember(IsRequired = true)]
public string AreaCode
{
get { return areaCode; }
set { areaCode = value; }
}
[DataMember(IsRequired = true)]
public string CprNumber
{
get { return cprNumber; }
set { cprNumber = value; }
}
[DataMember(IsRequired = false)]
public string PayingCustomerId
{
get { return payingCustomerId; }
set { payingCustomerId = value; }
}
[DataMember(IsRequired = true)]
public string PaymentCode
{
get { return paymentCode; }
set { paymentCode = value; }
}
[DataMember(IsRequired = false)]
public string LanguageCode
{
get { return languageCode; }
set { languageCode = value; }
}
#endregion
}
服务运行得很好,但相应的soap xml并不是我所想到的。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="test-contract" xmlns:test1="test-person">
<soapenv:Header/>
<soapenv:Body>
<test:CreateUpdateDebitorPerson>
<!--Optional:-->
<test:person>
<test1:Address1></test1:Address1>
<!--Optional:-->
<test1:Address2></test1:Address2>
<test1:AreaCode></test1:AreaCode>
<test1:City></test1:City>
<test1:CprNumber></test1:CprNumber>
<test1:FirstName></test1:FirstName>
<!--Optional:-->
<test1:LanguageCode></test1:LanguageCode>
<test1:LastName></test1:LastName>
<!--Optional:-->
<test1:PayingCustomerId></test1:PayingCustomerId>
<test1:PaymentCode></test1:PaymentCode>
<test1:PostalCode></test1:PostalCode>
<test1:SenderSystemId></test1:SenderSystemId>
</test:person>
</test:CreateUpdateDebitorPerson>
</soapenv:Body>
</soapenv:Envelope>
为什么元素属于test-contract而不属于接口中定义的testperson?有人可以帮帮我吗?
答案 0 :(得分:1)
因为元素本身(“&lt; person&gt;”)是在服务合同级别定义的,而不是在数据合同级别定义的。你得到&lt; test-contract:person&gt; (如果您在服务中使用它)或&lt; test-person:DebitorPerson&gt; (如果使用DataContractSerializer以独立方式序列化实例)。以某种方式混合两者(例如&lt; test-person:person&gt;)会不一致 - 为什么名称空间来自DataContract级别,而名称来自ServiceContract级别?