2012-03-29 187 views
0

我在我的windows phone应用程序中使用json-rpc.net的json-rpc客户端。 代码:JSON-RPC异常

var client = new AustinHarris.JsonRpc.JsonRpcClient(new Uri("http://www.raboof.com/projects/jayrock/demo.ashx")); 
var myObs = client.Invoke<string>("echo", "hello world", Scheduler.ThreadPool); 
myObs.Subscribe(
    onNext: _ => 
    { 
     Console.WriteLine(_.Result); 
    }); 
     } 

然后,我想获得的数据,应用程序退出与JsonReaderException:

Newtonsoft.Json.JsonReaderException 
    Message=Unexpected character encountered while parsing value: <. Line 0, position 0. 
    LineNumber=0 
    LinePosition=0 
    Path="" 
    StackTrace: 
     at Newtonsoft.Json.JsonTextReader.ParseValue() 
     at Newtonsoft.Json.JsonTextReader.ReadInternal() 
     at Newtonsoft.Json.JsonTextReader.Read() 
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter, Boolean inArray) 
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) 
     at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) 
     at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) 
     at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) 
     at Newtonsoft.Json.JsonConvert.DeserializeObject(String value) 
     at AustinHarris.JsonRpc.JsonRpcClient.<>c__DisplayClassa`1.<>c__DisplayClassc.<>c__DisplayClasse.<Invoke>b__9(IAsyncResult riar) 
     at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2) 
     at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadPool.WorkItem.doWork(Object o) 
     at System.Threading.Timer.ring() 
+0

如果它作为第一个字符返回'<',你确定它是一个JSON-RPC服务吗?看起来像REST + XML,XML-RPC或SOAP。 – 2012-04-04 08:40:44

回答

1

如果JSON-RPC客户端解析器代码中断接收响应时,它死的第一个字符(Line 0, position 0)这恰好是一个<字符,你不得不怀疑该服务已经返回XML。

您确定您正在与正确的服务端点通话吗?有正确的协议?