C# 如何从WCF服务中清除不需要的字符?

C# 如何从WCF服务中清除不需要的字符?,c#,wcf,C#,Wcf,我有一个WCF服务,它以XML格式向客户端发送响应。当我用soapui测试它时,它给了我一些额外的字符。同样,注释中的名称空间也需要删除它们。我不知道他们从哪里来。 这是我得到的回应: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <ProcessXMLResponse xmlns="https://cf.ctr.com">

我有一个WCF服务,它以XML格式向客户端发送响应。当我用soapui测试它时,它给了我一些额外的字符。同样,注释中的名称空间也需要删除它们。我不知道他们从哪里来。 这是我得到的回应:

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

没有额外的字符。当您通过将内容反序列化为具体类型或解析架构(例如,某个架构中的名称空间和属性名称)来反转流程时,可能需要额外的信息

在我看来,您正在从某种形式的XSD验证引擎获得注释,这将为您提供错误原因的完整解释,例如,元素无效-值“104213”根据其数据类型“UnsignedShort”无效-模式约束失败

在网络上以字符串形式传递XML不是一个好主意。删除它们更为复杂,而且可能是错误的方向

最后,你为什么要关心它在电线上的外观?如果你的伴侣向你发送了一大堆你评论中的问题,你必须在你收到这些问题后将它们转化成对你有意义的东西,不管它在网上看起来如何