我嘗試通過ksoap2-android將複雜類型發送到wcf服務。 Basicly我遵循的指導http://seesharpgears.blogspot.de/2010/10/ksoap-android-web-service-tutorial-with.html 我能夠收到來自Web服務的複雜數據類型,但是當我嘗試發送一個我得到以下錯誤:如何通過ksoap2-android發送複雜類型到wcf服務? - 如何配置wcf服務?
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)
{
...
}
我附上我的android代碼,以防萬一我搞砸了。
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();