我尝试通过ksoap2-android将复杂类型发送到wcf服务。 基本上我遵循了指南http://seesharpgears.blogspot.de/2010/10/ksoap-android-web-service-tutorial-with.html 我能够从Web服务接收复杂的数据类型,但是当我尝试发送一个时,我收到以下错误:
a:DeserializationFailed
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:es.
The InnerException message was 'Error in line 1 position 373. Element 'http://tempuri.org/:es' contains data from a type that maps to the name 'http://tempuri.org/:EventSeries'.
The deserializer has no knowledge of any type that maps to this name.
Consider using a DataContractResolver or add the type corresponding to 'EventSeries' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details.
问题是如何解决这个问题?信封中会返回错误。 正如我在教程中所做的所有事情以及接收复杂类型的工作一样,我认为错误是在服务器端产生的,但不幸的是我对wcf服务一无所知。我必须在wcf服务上做些什么来改变它?
我们尝试了类似
的内容[ServiceKnownType(typeof(EventSeries))]
如错误消息中所述,但没有帮助
Web服务上的方法看起来像那样
public int InsertEventSeriesForAndroidVIntES(EventSeries es)
{
...
}
我附上我的安卓代码,以防我搞砸了。
SoapObject request = new SoapObject("http://tempuri.org/, "InsertEventSeriesForAndroidVIntES");
EventSeries es = new EventSeries(10, "call Test");
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("es");
propertyInfo.setNamespace("http://tempuri.org");
propertyInfo.setValue(es);
propertyInfo.setType(EventSeries.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(request.getNamespace(), "EventSeries", EventSeries.class);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("http://tempuri.org/IDiversityService/InsertEventSeriesForAndroidVIntES", envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
答案 0 :(得分:3)
我知道答案来得非常晚,但希望其他人也可以从中受益。 我已按照以下教程http://seesharpgears.blogspot.com.es/2010/10/ksoap-android-web-service-tutorial-with.html发送复杂类型并收到类似错误。 问题是由默认命名空间引起的,因为ksoap不知道如何映射对象。 尝试通过在服务上,服务接口上以及在服务方法上传递的对象上设置自己的命名空间来定义自己的命名空间:
还要调整客户端代码,以便通过将tempuri.org替换为您自己的:yournamespace.org来匹配新的命名空间。 有关如何消除tempuri命名空间的更多详细信息,请阅读以下帖子:http://blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx