2012-01-26 22 views
0

私は、ksoap2ライブラリを使用してAndroidデバイス経由でWebサービスに接続しようとしています。私は2つの異なるサービスでうまく動作するようにしましたが、今は問題に遭遇しました。プリミティブ型の代わりにオブジェクトを渡すと、エラーが発生します。私はKvmSerializableを使ってクラスを実装しましたが、まだ運がありません。ここで動作するWebブラウザから送信されたリクエストのxmlと、動作しないAndroidデバイスから送信されたリクエストのxmlがあります。すべての提案は素晴らしいでしょう!Android WSDL Webサービスksoap2

ブラウザ

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Body> 
    <CreateTour xmlns="http://tempuri.org/"> 
     <SecurityKey>2b9fac80-97ce-4483-b9e8-c1816656e1db</SecurityKey> 
     <OriginDetails xmlns:d4p1="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <d4p1:Creator>3</d4p1:Creator> 
      <d4p1:CreatorOS>1</d4p1:CreatorOS> 
      <d4p1:CreatorVersion>1.0.0.18191</d4p1:CreatorVersion> 
      <d4p1:IP>192.168.1.61</d4p1:IP> 
      <d4p1:UserAgent>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7</d4p1:UserAgent> 
     </OriginDetails> 
     <Details xmlns:d4p1="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <d4p1:Baths>1.00</d4p1:Baths> 
      <d4p1:Beds>6</d4p1:Beds> 
      <d4p1:City>Knoxville</d4p1:City> 
      <d4p1:Country>US</d4p1:Country> 
      <d4p1:CreatedDate>2012-01-24T17:50:09.0541149-05:00</d4p1:CreatedDate> 
      <d4p1:Description>Another test</d4p1:Description> 
      <d4p1:Garage>9</d4p1:Garage> 
      <d4p1:MLSID>400</d4p1:MLSID> 
      <d4p1:ModifiedDate>2012-01-24T17:50:09.0541149-05:00</d4p1:ModifiedDate> 
      <d4p1:MusicFile>/music/magic.mp3</d4p1:MusicFile> 
      <d4p1:Price>400</d4p1:Price> 
      <d4p1:PropertyType>0</d4p1:PropertyType> 
      <d4p1:SF>400</d4p1:SF> 
      <d4p1:Schools i:nil="true" /> 
      <d4p1:ShowAddress>true</d4p1:ShowAddress> 
      <d4p1:ShowPrice>true</d4p1:ShowPrice> 
      <d4p1:State>TN</d4p1:State> 
      <d4p1:Status i:nil="true" /> 
      <d4p1:Street>9111 Cross Park Drive</d4p1:Street> 
      <d4p1:Title>Test</d4p1:Title> 
      <d4p1:TourID i:nil="true" /> 
      <d4p1:YearBuilt i:nil="true" /> 
      <d4p1:Zip>37923</d4p1:Zip> 
     </Details> 
    </CreateTour> 
</s:Body> 

アンドロイド

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"> 
<v:Header /> 
<v:Body> 
    <CreateTour xmlns="http://tempuri.org/" id="o0" c:root="1"> 
     <SecurityKey i:type="d:string">641c38a3-b290-45db-b2d4-8c4edac5934a</SecurityKey> 
     <OriginDetails i:type="d:anyType"> 
      <Creator i:type="d:int">4</Creator> 
      <CreatorOS i:type="d:int">6</CreatorOS> 
      <CreatorVersion i:type="d:string">1.0</CreatorVersion> 
      <IP i:type="d:string">192.168.1.222</IP> 
      <UserAgent i:type="d:string"></UserAgent> 
     </OriginDetails> 
     <Details i:type="d:anyType"> 
      <Baths i:type="d:int">1</Baths> 
      <Beds i:type="d:int">2</Beds> 
      <City i:type="d:string">Cleveland</City> 
      <Country i:type="d:string">US</Country> 
      <CreatedDate i:type="d:string"></CreatedDate> 
      <Description i:type="d:string"></Description> 
      <Garage i:type="d:int">2</Garage> 
      <MLSID i:type="d:string">44</MLSID> 
      <ModifiedDate i:type="d:string"></ModifiedDate 
      ><MusicFile i:type="d:string"></MusicFile> 
      <Price i:type="d:int">400</Price> 
      <PropertyType i:type="d:int">0</PropertyType> 
      <SF i:type="d:int">777</SF> 
      <Schools i:type="d:string"></Schools> 
      <ShowAddress i:type="d:boolean">true</ShowAddress> 
      <ShowPrice i:type="d:boolean">true</ShowPrice> 
      <State i:type="d:string">TN</State> 
      <Status i:type="d:int">0</Status> 
      <Street i:type="d:string">200 Post Road</Street> 
      <Title i:type="d:string">Android Test Tour</Title> 
      <TourID i:type="d:int">0</TourID> 
      <YearBuilt i:type="d:int">0</YearBuilt> 
      <Zip i:type="d:string">37362</Zip> 
     </Details>   
    </CreateTour> 
</v:Body> 

答えて

1

私は、過去に同様の問題を抱えていました。私は、あなたに私は私のアプリケーションとどのように私がやった中で修正しなければならなかった一部の例を与えるあなたは、あなたのケースでこれらの手順を行ったかどうかを確認します:
WSDLであった:

<message name="invokeService"> 
    <part name="serviceName" type="xsd:string"/> 
    <part name="documents" type="tns:uriList"/> 
    <part name="literalDocs" type="ns1:stringArray"/> 
    <part name="connID" type="xsd:long"/> 
    <part name="gateParams" type="tns:gateRuntimeParameterArray"/> 
    <part name="userCtx" type="tns:userContext"/> 
</message> 



の1-チェックをKvmSerializableを実装するあなたのクラスが正確に何が不足して定義されていない場合(これは複雑なタイプのためにcrucialeです)

あなたが必要とするすべての必要な石鹸オブジェクトのプロパティを2-追加、:だから私は、次の手順を実行しなければなりませんでした例えば私の場合:

など
//for the part: <part name="serviceName" type="xsd:string"/> 
SoapObject.addProperty("serviceName", whateverServiceNameItWas); 

//for the part: <part name="documents" type="tns:uriList"/>,where uriList was a complex type 
PropertyInfo pi = new PropertyInfo(); 
pi.setName("documents"); 
pi.setValue(usrOptPr.getDocuments()); 
pi.setType(UriList.class); 
sobj.addProperty(pi); 

... 3-ビルドしenveloppe:

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
soapEnvelope.setOutputSoapObject(SoapObject); 

、4-は、複雑なタイプ間のマッピング(すなわちローカルkvmserializableを実装するクラス、およびWeb上の実際のマッチングクラスを追加しますサービス)

//--------------------------------------------------------------------------------------- 
// MAPPINGS: 
// A mapping tells the ksoap what class to generate. 
// Complex data types that are not mapped are generated as SoapObjects. 
// The mapping is required for both the request and the response. 
//--------------------------------------------------------------------------------------- 

//for example the UriList above  
soapEnvelope.addMapping(theNamespace, UriList.class.getSimpleName(), UriList.class); 

、5-マーシャリングを追加します(マーシャリングが上の非整列化するために、データの流れにオブジェクトを変更するにはJavaのシリアライズを使用していますウェブサービス)

Marshal floatMarshal = new MarshalFloat(); 
floatMarshal.register(soapEnvelope); 

5,6使用AndroidHttpTransportが
UPDATE
Webサービスを呼び出すために、私はまた、あなたがブラウザの要求を持っていることに気づいた:。

<d4p1:Schools i:nil="true" /> 

アンドロイドでいる間:

<Schools i:type="d:string"></Schools> 

時にはksoap2バグwiこのシナリオでは、私は同じケースを持っていたので、kvmserializableを実装する特定のクラスからこのparam(つまり学校)を削除しました(コメントアウトしました。 "getPropertyCount"や "getPropertyInfo"のようなクラス内の他のものをこの変更に合わせて変更してください)。私はそれが働いたので、それを試み、私に知らせてください。

+0

実際には名前空間の問題であることが判明しました。子要素からd4p1を削除するためにWebサービスでそれを変更したら、うまくいきました。ありがとうございました! – tbaxter120

関連する問題