C#asmx WebService投放问题

时间:2018-10-09 12:09:12

标签: c# web-services class asmx

我有一个C#asmx Web服务WP.asmx,它是字符串方法`Authorisation(string PMSRequest)

[ScriptMethod(UseHttpGet = true)]
[WebMethod]
public string Authorisation(string PMSRequest)

将JSON字符串反序列化为名为Details的类

class Details
    {
        public string Number { get; set; }
    }

此处:

Details obj = JsonConvert.DeserializeObject<Details>(PMSRequest)

并最终重新输入字符串。

我正在尝试通过浏览器调用它

https://example.net/WP.asmx/Authorisation?PMSRequest="{\"Number\":\"5413\"}"

强文本 但是我得到一个错误

Could not cast or convert from System.String to My.Web.MyService.WP+Details

Newtonsoft.Json.JsonSerializationException: Error converting value 
   at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
   at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)

当我在C#Windows Form测试应用程序中使用相同的代码时,它可以正常工作

0 个答案:

没有答案