我有一个WCF服务,它以XML格式向客户端发送响应。当我用Soap UI测试它时,它给了我一些额外的特征。喜欢并在评论中命名空间是' https://cf.ctr.com:DealerId'需要删除它们。我不确定他们来自哪里。 这是我得到的回应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ProcessXMLResponse xmlns="https://cf.ctr.com">
<ProcessXMLResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<StatusCode>201</StatusCode>
<StatusDescription>XML Validation Fails</StatusDescription>
<comments xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string/>
<a:string>The element 'Collateral' in namespace 'https://cf.ctr.com' has invalid child element 'VIN' in namespace 'https://cf.ctr.com'. List of possible elements expected: 'Vehicle' in namespace 'https://cf.ctr.com'.</a:string>
<a:string>The 'https://cf.ctr.com:DealerId' element is invalid - The value '104213' is invalid according to its datatype 'UnsignedShort' - The Pattern constraint failed.</a:string>
<a:string>The 'https://https://cf.ctr.com:EmploymentPeriodInMonth' element is invalid - The value '0' is invalid according to its datatype 'Integer' - The MinInclusive constraint failed.</a:string>
<a:string>The 'https://cf.ctr.com:Name' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.</a:string>
</comments>
<RemoteRefNumber>104213C3C4B606-2A10-46F4-87FA-E23</RemoteRefNumber>
</ProcessXMLResult>
</ProcessXMLResponse>
这是我的合同:
[DataContract(Namespace = "https://https://cf.ctr.com")]
public class PartnerRequest
{
// ------------------------------------------------------------------- Username and Password in SOAP's Header - START
[DataMember(Name = "username",Order=1)]
public string username { get; set; }
[DataMember(Name = "password",Order=2)]
public string password { get; set; }
// ------------------------------------------------------------------- Username and Password in SOAP's Header --- END
// Body
[DataMember(Name = "PartnerID", Order=3)]
public int PartnerID { get; set; }
[DataMember(Name = "PartnerName",Order=4)]
public string PartnerName { get; set; }
[DataMember(EmitDefaultValue = false,Name = "CFCConnect", Order = 5)]
public CFCConnect CFCConnect { get; set; }
}
[DataContract(Namespace = "https://cf.ctr.com")]
public class PartnerAuthentication
{
public PartnerAuthentication()
{
}
public PartnerAuthentication(PartnerAuthentication partner)
{
this.Authenticated = partner.Authenticated;
this.StatusCode = partner.StatusCode;
this.StatusDescription = partner.StatusDescription;
this.comments = partner.comments;
this.RemoteRefNumber = partner.RemoteRefNumber;
}
//[MessageBodyMember(Order = 1, Namespace = "https://cf.ctr.com")]
public bool Authenticated { get; set; }
[DataMember(Name = "StatusCode", Order = 1)]
public int StatusCode { get; set; }
[DataMember(Name = "StatusDescription", Order = 2)]
public string StatusDescription { get; set; }
[DataMember(Name = "comments", Order = 3)]
public List<string> comments { get; set; }
[DataMember(Name = "RemoteRefNumber", Order = 4)]
public string RemoteRefNumber { get; set; }
答案 0 :(得分:0)
没有“额外”字符。当您通过将内容反序列化为具体类型或解析模式时,可能需要“额外”信息。 “'https://cf.ctr.com:DealerId'”是某些架构中的命名空间和属性名称。
在我看来,您正在从某种形式的XSD验证引擎获得评论,它将为您提供完整的解释,说明出现问题的原因,例如: “'https://cf.ctr.com:DealerId'元素无效 - 根据数据类型'UnsignedShort',值'104213'无效。 - 模式约束失败。”
将XML作为字符串传递给线路并不是一个好主意。删除它们更复杂,可能是错误的方向。
最后,你为什么要关注它在电线上的样子?如果你的伴侣在你的评论中向你发送问题的完整堆栈转储,你必须在收到它后将它们转换成对你有意义的东西,无论它在网上看起来如何。