【发布时间】:2015-09-03 13:09:43
【问题描述】:
我有总是返回的 WCF 服务:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"> JSON STRING </string>
我只想要 JSON STRING 片段。我在stackoverflow中阅读了一些帖子并尝试了解决方案,但我无处可去。这是我的代码:
[ServiceContract]
public interface IUserService
{
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetUserById?x={uid}")]
string getUserByUID(string uid);
接口实现:
public class UserService : IUserService
{
public string getUserByUID(string uid)
{
UserDAO mUserDAO = UserService.getUserDAO();
User mUser = mUserDAO.getUserByUID(Convert.ToInt64(uid));
if (mUser != null)
{
mUserDAO.close();
return JsonConvert.SerializeObject(mUser);
}
网页配置:
<behavior name="restfulBehavior">
<webHttp />
</behavior>
Retrofit 发出的调用:
D/Retrofit﹕ ---> HTTP GET http:http://localhost/UserService.svc/GetUserById?x=1
D/Retrofit﹕ Content-Type: application/json
D/Retrofit﹕ ---> END HTTP (no body)
从服务器返回
D/Retrofit﹕ <--- HTTP 200 http://localhost/UserService.svc/GetUserById?x=1 (92ms)
D/Retrofit﹕ Content-Length: 446
D/Retrofit﹕ Content-Type: application/xml; charset=utf-8
D/Retrofit﹕ Server: Microsoft-IIS/7.5
D/Retrofit﹕ X-Powered-By: ASP.NET
D/Retrofit﹕ Date: Thu, 18 Jun 2015 03:32:53 GMT
D/Retrofit﹕ OkHttp-Selected-Protocol: http/1.1
D/Retrofit﹕ OkHttp-Sent-Millis: 1434598232505
D/Retrofit﹕ OkHttp-Received-Millis: 1434598232588
D/Retrofit﹕ <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{JSON STRING}</string>
D/Retrofit﹕ <--- END HTTP (446-byte body)
我在这里错过了什么?
提前谢谢你。
【问题讨论】:
-
你如何调用你的服务?
-
@YeldarKurmangaliyev,我正在使用改造。我添加了调用并返回数据。谢谢。
标签: c# json web-services wcf