2016-04-16 12 views
1

私はアンドロイド開発の新入生です。今日私はKSOAP2を使ってサーバー上でWCFを完成させました。まず、WCFをWindowsフォームで使用しようとします。正常に実行され、データがアップロードされました。それから私はKSOAP2でWCFを使用します。文字列はうまく送信できません。エラーは次のとおりです。 メソッドが 'org.ksoap2.SoapFault'例外をスローしました。 エラーのdetialは次のとおりです。 a:InternalServiceFault 値をnullにすることはできません。 パラメータ名:sAndroid用WCF(webservice)

サーバプログラムおよびアンドロイドプログラムに「s」というパラメータはありません。 .NETのビジョンはフレームワーク4.0です。 .NET Framework 4.5を使用している場合、アンドロイドはKSOAP2でそれを使用できます。 しかし、私は4.0を使用する必要があります どうすればこの問題を解決できますか? 乾杯。

アンドロイドのコードを以下に示します。

transferthread = new Thread(new Runnable() { 
      @Override 
      public void run() { 
       while (true) 
       { 

         SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME); 
         int a = 1; 
         request.addProperty("userid",a); 
         request.addProperty("healthData",info); 
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10); 
         envelope.dotNet = true; 
         envelope.bodyOut = request; 
         envelope.setOutputSoapObject(request); 
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
         androidHttpTransport.debug = true; 
         try { 
          androidHttpTransport.call(SOAP_ACTION, envelope); 
          // final SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 
          envelope.getResponse(); 
          Log.e("str",envelope.getResponse().toString()); 
          a=1; 
          //Log.e("aaa",envelope.getResponse().toString()); 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } catch (XmlPullParserException e) { 
          e.printStackTrace(); 
         } 



        try { 
         Thread.sleep(5000); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } 


       } 

      } 
     }); 
     transferthread.start(); 

私はksoap2の問題だと思います。

答えて

0

私の答えは、Androidの使用WCFを実装する方法に関するあなたの質問の別の代替ソリューションです。私はKSOAP2で試してみました。何らかの理由で(私は忘れてしまった)私はそれを使用してあきらめます。

これは私が同じことをするためにやっていることです。

Wizdler(Chrome拡張機能)をインストールしてエンベロープを生成できます。ペーストをエンベロープコードにコピーします。

asynctaskでgetYourDataを呼び出します。

public ArrayList<YourData> getYourData(String username, String password) { 
ArrayList<YourData> resultList; 
String resultData; 
try { 
    //Put your envelope here. 
    final String envelope = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + 
      " <Body>\n" + 
      "  <Something xmlns=\"http://www.example.com/RemoteServices/url/\">\n" + 
      "   <!-- Optional -->\n" + 
      "   <request>\n" + 
      "    <Authentication xmlns=\"http://schemas.datacontract.org/RemoteServicesv2.Core\">\n" + 
      "     <Password>" + 
      password + 
      "</Password>\n" + 
      "     <Username>" + 
      username + 
      "</Username>\n" 
      "  </Something>\n" + 
      " </Body>\n" + 
      "</Envelope>"; 

    resultData = CallWebService(URL, "http://www.example.com/webserviceURL", envelope); 
    Log.e("resultData for Something", ""+resultData); 
    resultList = parseFunction(resultData); 
} catch (Exception e) { 
    resultList = null; 
} 
return resultList; 

}

// How to send SOAP envelope to web service 
private String CallWebService(String url, 
           String soapAction, 
           String envelope) { 
    final DefaultHttpClient httpClient = new DefaultHttpClient(); 
    // request parameters 

    HttpParams params = httpClient.getParams(); 
    HttpConnectionParams.setConnectionTimeout(params, 20000); 
    HttpConnectionParams.setSoTimeout(params, 25000); 
    // set parameter 
    HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true); 

    // POST the envelope 
    HttpPost httppost = new HttpPost(url); 
    // add headers 
    httppost.setHeader("soapaction", soapAction); 
    httppost.setHeader("Content-Type", "text/xml; charset=utf-8"); 

    String responseString = ""; 
    try { 

     // the entity holds the request 
     HttpEntity entity = new StringEntity(envelope); 
     httppost.setEntity(entity); 

     // Response handler 

     ResponseHandler<String> rh = new ResponseHandler<String>() { 
      // invoked when client receives response 

      public String handleResponse(HttpResponse response) 
        throws ClientProtocolException, IOException { 

       // get response entity 
       HttpEntity entity = response.getEntity(); 


       // read the response as byte array 
       StringBuffer out = new StringBuffer(); 
       byte[] b = EntityUtils.toByteArray(entity); 

       // write the response byte array to a string buffer 
       out.append(new String(b, 0, b.length)); 

       return out.toString(); 
      } 
     }; 

     responseString = httpClient.execute(httppost, rh); 


    } catch (Exception e) { 
     Log.v("exception", e.toString()); 
    } 

    String xml = responseString.toString(); 
    // close the connection 
    System.out.println("xml file ------" + xml); 
    httpClient.getConnectionManager().shutdown(); 
    return responseString; 
} 
関連する問題