2012-03-23 53 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