2012-03-23 64 views
1

我尝试通过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(); 

回答

3

我知道答案真的很晚,但希望别人可能会从中受益。 我按照以下教程http://seesharpgears.blogspot.com.es/2010/10/ksoap-android-web-service-tutorial-with.html发送复杂类型并收到类似的错误。 这个问题是由于默认的命名空间造成的,因为ksoap不知道如何映射这些对象。 试图通过将它的服务来定义自己的命名空间,服务接口和正在上的服务方法传递的对象上:

  • 装修与服务:ServiceBehavior(命名空间= HTTP:// yournamespace.org/)]与
  • 装饰服务接口:[的ServiceContract(命名空间= http://yournamespace.org/)]
  • 与装饰物件:[DataContract(命名空间= http://yournamespace.org /)]

另外一个调整您的客户端代码,以便通过将tempuri.org替换为您自己的:yournamespace.org来匹配新的名称空间。 有关如何消除temp名称空间的详细信息,请阅读以下文章:http://blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx