【发布时间】:2013-05-27 03:50:52
【问题描述】:
我正在像这样发出朋友/ID 电话:
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。
更新 WCF 配置,根据要求:
<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() 它给了我 T(在这种情况下为 IFriends)。 -
那么你的 wcf 配置、绑定等怎么样?
-
@TommyGrovnes 查看问题更新。
-
身份验证怎么样?
标签: json wcf rest serialization twitter