我發出的朋友/ IDS稱,像這樣:WCF REST JSON收集空與Twitter
GET /1.1/friends/ids.json?screen_name=blablabla HTTP/1.1
有效響應發出:
{"ids":[97500486,32947624,8884440,2022687,28741369,33978239,10312111,950922,7682036,21688137,7696145,15876098],"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0"}
我的界面看起來是這樣的:
[OperationContract(Name = "ids.json")]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate="ids.json?user_id={userId}&screen_name={screenName}")]
FriendsIdsResponse Ids(long? userId, string screenName);
[DataContract]
public class FriendsIdsResponse
{
public FriendsIdsResponse()
{
}
[DataMember(Name = "ids")]
public long[] Ids { get; set; }
[DataMember(Name = "previous_cursor")]
public int PreviousCursor { get; set; }
[DataMember(Name = "next_cursor")]
public int NextCursor { get; set; }
}
無論什麼類型的Ids是(long [],IList,List等),它總是返回null。如果我將它實例化爲ctor中的空列表,它的Count == 0。
UPDATE WCF CONFIGS,如要求:
<system.serviceModel>
<client>
<endpoint contract="TA.Twitter.Service.IFriends, TA.Twitter.Interfaces"
address="https://api.twitter.com/1.1/friends/"
binding="webHttpBinding" bindingConfiguration="WebHttpBinding"
></endpoint>
</client>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding" allowCookies="true">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
能否請您提供您所使用調用Twitter的API和反序列化響應代碼。你的合同和界面很好,所以它必須是客戶端代碼。 –
@TommyGrovnes但我沒有使用任何自定義代碼,它都是WCF。從本質上講,我創建了一個ChannelFactory,然後創建了一個.CreateChannel()(這裏是IFriends)。 –
那麼你的wcf配置如何,綁定等? –