我使用System编写web服务。ServiceModel System.ServiceModel.Web System.ServiceModel.Activation命名空间
[XmlSerializerFormat]
[OperationContract]
[WebGet(UriTemplate = Routing.GetClientRoute, BodyStyle = WebMessageBodyStyle.Bare)]
string GetClientNameById(string Id);
我用这个类描述数据:
[XmlRoot("ServiceXmlReply")]
public class ServiceXmlReply
{
[XmlElement]
public string Name;
}
问题是响应,这是我从服务收到的。它看起来像这样:
"<?xml version="1.0" encoding="utf-8"?>
<string>
<ServiceXmlReply xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Igor<Name>
<ServiceXmlReply>
</string>"
你可以看到这里不应该有"string"标签,但它是。因为它不能反序列化响应和获取数据。
类在服务器端和客户端是相同的
您的操作契约定义GetClientNameById的响应类型为字符串。结果是返回类型字符串的内容是一个序列化的xml。
要使它工作,你应该这样做:
- 将操作的返回类型更改为ServiceXmlReply或
- 放弃使用ServiceXmlReply。在服务端和客户端使用字符串代替。