0

コールアウトからのPOSTをサポートできるIIS7でホストされる単純なHTTPC#RESTful Webサービスを作成する必要があり、POSTデータの形式が適切に処理されていないようです。データメンバー名の要件は、custom-1のようにダッシュが含まれていることです。私の問題は、custom-10以上のデータメンバー名がデータに対してnullを与えるだけであるということです。custom-1からcustom-9までは問題ありません。

誰かが助けてくれるなら、私はそれを感謝します!!!

POSTデータに必要な形式は次のとおりです。

 <person-search-request xmlns="someurl"> 
    <person>
        <custom-1 />
        <custom-2 />
        <custom-3 />
        <custom-4 />
        <custom-5 />
        <custom-6 />
        <custom-7 />
        <custom-8 />
        <custom-9 />
        <custom-10 />
        <custom-11 />
        <custom-12 />
        <custom-13 />
        <custom-14 />
        <custom-15 />
        <custom-16 />
        <custom-17 />
        <custom-18 />
        <custom-19 />
        <custom-20 />
      </person>
     </person-search-request>

私のWebサービスデータコントラクトは次のようになります。

    [CollectionDataContract(Name = "person-search-request", Namespace="")]
    public class PersonsRequest : List<Person>
    { }

    [CollectionDataContract(Name = "person-search-response", Namespace="")]
    public class PersonsResponse : List<Person>
    { }

    [DataContract(Name = "person", Namespace = "")]
    public class Person
    {
        public Person()
        {
            Custom14 = String.Empty;
            Custom13 = String.Empty;
            Custom15 = String.Empty;
            Custom16 = String.Empty;
            Custom17 = String.Empty;
            Custom18 = String.Empty;
            Custom19 = String.Empty;
            Custom20 = String.Empty;
            Custom7 = String.Empty;
            Custom8 = String.Empty;
            Custom9 = String.Empty;
            Custom1 = String.Empty;
            Custom10 = String.Empty;
            Custom11 = String.Empty;
            Custom12 = String.Empty;
            Custom3 = String.Empty;
            Custom4 = String.Empty;
            Custom5 = String.Empty;
            Custom6 = String.Empty;
        }


        [DataMember(Name = "custom-14")]
        public string Custom14 { get; set; }
        [DataMember(Name = "custom-7")]
        public string Custom7 { get; set; }
        [DataMember(Name = "custom-8")]
        public string Custom8 { get; set; }
        [DataMember(Name = "custom-9")]
        public string Custom9 { get; set; }
        [DataMember(Name = "custom-13")]
        public string Custom13 { get; set; }
        [DataMember(Name = "custom-15")]
        public string Custom15 { get; set; }
        [DataMember(Name = "custom-16")]
        public string Custom16 { get; set; }
        [DataMember(Name = "custom-17")]
        public string Custom17 { get; set; }
        [DataMember(Name = "custom-18")]
        public string Custom18 { get; set; }
        [DataMember(Name = "custom-19")]
        public string Custom19 { get; set; }
        [DataMember(Name = "custom-20")]
        public string Custom20 { get; set; }
        [DataMember(Name = "custom-10")]
        public string Custom10 { get; set; }
        [DataMember(Name = "custom-11")]
        public string Custom11 { get; set; }
        [DataMember(Name = "custom-12")]
        public string Custom12 { get; set; }
        [DataMember(Name = "custom-1")]
        public string Custom1 { get; set; }
        [DataMember(Name = "custom-2")]
        public string Custom2 { get; set; }
        [DataMember(Name = "custom-3")]
        public string Custom3 { get; set; }
        [DataMember(Name = "custom-4")]
        public string Custom4 { get; set; }
        [DataMember(Name = "custom-5")]
        public string Custom5 { get; set; }
        [DataMember(Name = "custom-6")]
        public string Custom6 { get; set; }
        /// <summary>


    }

私のサービスエンドポイントは次のように設定されています。

    [ServiceBehavior(IncludeExceptionDetailInFaults = true), AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed), ServiceContract]
public partial class Service
{

     [WebHelp(Comment = "Person POST")]
    [WebInvoke(UriTemplate = "person/v1.0/fetch", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
    [OperationContract]
    public PersonsResponse FetchPerson(PersonsRequest request)
    {
            ....
     }

}

投稿データは次のようになります(Fiddlerを使用してテストします)。

    <person-search-request> 
    <person>
        <custom-1>1</custom-1>
        <custom-2>2</custom-2>
        <custom-3>3</custom-3>
        <custom-4>4</custom-4>
        <custom-5>5</custom-5>
        <custom-6>6</custom-6>
        <custom-7>7</custom-7>
        <custom-8>8</custom-8>
        <custom-9>9</custom-9>
        <custom-10>10</custom-10>
        <custom-11>11</custom-11>
        <custom-12>12</custom-12>
        <custom-13>13</custom-13>
        <custom-14>14</custom-14>
        <custom-15 />
        <custom-16 />
        <custom-17 />
        <custom-18 />
        <custom-19 />
        <custom-20 />
     </person>
</person-search-request>

データは、10〜20個のカスタムタグにnullが含まれるエンドポイントに送られます。誰もが理由を知っていますか?:(

これは、メソッドに渡されたリクエストオブジェクトからデバッグしたときに表示されるものです。

     Custom1    "1" string
    Custom10    null    string
    Custom11    null    string
    Custom12    null    string
    Custom13    null    string
    Custom14    null    string
    Custom15    null    string
    Custom16    null    string
    Custom17    null    string
    Custom18    null    string
    Custom19    null    string
    Custom2 "2" string
    Custom20  null  string
    Custom3 "3" string
    Custom4 "4" string
    Custom5 "5" string
    Custom6 "6" string
    Custom7 "7" string
    Custom8 "8" string
    Custom9 "9" string
4

1 に答える 1

0

order 属性を使用してこれを修正できました。まだまだ予測不能な行動。他の誰かがより良い説明を持っているなら、それはありがたいです!!!

とにかく、ここに修正があります (1 と 2 スロットを使用し始めている他の重要でないメンバーがいます):

        [DataMember(Name = "custom-1", Order = 3)]
        public string Unused1 { get; set; }
        [DataMember(Name = "custom-2", Order = 4)]
        public string Unused2 { get; set; }
        [DataMember(Name = "custom-3", Order = 5)]
        public string Unused3 { get; set; }
        [DataMember(Name = "custom-4", Order = 6)]
        public string Unused4 { get; set; }
        [DataMember(Name = "custom-5", Order = 7)]
        public string Unused5 { get; set; }
        [DataMember(Name = "custom-6", Order = 9)]
        public string Unused6 { get; set; }
        [DataMember(Name = "custom-7", Order = 10)]
        public string License { get; set; }
        [DataMember(Name = "custom-8", Order = 11)]
        public string LicenseState { get; set; }
        [DataMember(Name = "custom-9", Order = 12)]
        public string Tax { get; set; }
        [DataMember(Name = "custom-10", Order = 13)]
        public string Unused10 { get; set; }
        [DataMember(Name = "custom-11", Order = 14)]
        public string Unused11 { get; set; }
        [DataMember(Name = "custom-12", Order = 15)]
        public string Unused12 { get; set; }
        [DataMember(Name = "custom-13", Order = 16)]
        public string ProfDesignation { get; set; }
        [DataMember(Name = @"custom-14", Order = 17)]
        public string NPI { get; set; }
        [DataMember(Name = "custom-15", Order = 18)]
        public string Address1 { get; set; }

        [DataMember(Name = "custom-16", Order = 19)]
        public string Address2 { get; set; }

        [DataMember(Name = "custom-17", Order = 20)]
        public string Address3 { get; set; }

        [DataMember(Name = "custom-18", Order = 21)]
        public string City { get; set; }

        [DataMember(Name = "custom-19", Order = 22)]
        public string State { get; set; }

        [DataMember(Name = "custom-20", Order = 23)]
        public string Zip { get; set; }
于 2012-08-24T16:34:16.750 に答える