2017-01-27 5 views
-1

を送信:Javaはこんにちは、私はこのようしようとしている、文字列のXMLにリクエストを送信必要なXML文字列

final String SOAP_ACTION  = "http://tempuri.org/Search"; 
final String METHOD_NAME  = "Search"; 
final String NAME_SPACE  = "http://tempuri.org/"; 
final String URL    = "https://www.url.com/xxx/xxx.asmx?wsdl"; 
String  XML    = "<data><id>"+ paramId +"</id><phone>"+ paramPhone +"</phone></data>"; 
SoapObject request   = new SoapObject(NAME_SPACE, METHOD_NAME); 
request.addProperty("", XML); //I don't know how to pass it here 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet        = true; 
envelope.setOutputSoapObject(request); 
HttpTransportSE    httpTransport = new HttpTransportSE(URL); 
try { 
     httpTransport.call(SOAP_ACTION, envelope); 
     Object res = envelope.getResponse(); 
     if (res instanceof SoapPrimitive) { 
      return (((SoapPrimitive) res).toString()); 
     } 
     return String.valueOf(res); 
    } catch (IOException | XmlPullParserException ex) { } 

をしかし、私はこのエラーを取得しています:事前に

SoapFault - faultcode:
'soap:Server' faultstring: 'Server was unable to process request.
---> Object reference not set to an instance of an object.'
faultactor: 'null' detail: [email protected]

感謝を。

+1

*:?*あなたは 'wsdl' URLにSOAPメッセージを送信しません。 '?wsdl' URLは、WebサービスエンドポイントのWSDLを取得するために使用されます。 – Andreas

+0

サーバーからNullPointerException(または同等のもの)が発生したというエラーメッセージがサーバーから受信しています。詳細については、サーバーコードおよび/またはログファイルを確認する必要があります。 – Andreas

+0

* FYI:*あなたがXMLエスケープを自分で処理しない限り、文字列連結を使用してXMLを構築することは本当に悪い考えです。誰かが自分の電話番号に '<'を入力すると、悪いXMLで終わるでしょう。確かに、電話番号の検証ロジックはそれを守るかもしれないが、あなたはいつもそれに頼ることはできない。 – Andreas

答えて

0

Javaでは、wsimportを使用してSOAPスタブを作成できます。それははるかに簡単になります。スタブはすでにあなたのためにいくつかの変換タスクを行います。

StringパラメータにXML要素が含まれている場合、URLエンコードされます。少なくとも<は、& < &gt;と表示されます。

XML = XML.replace("<", "&lt;"); 
XML = XML.replace(">", "&gt;"); 
request.addProperty("", XML); //now encoded, but server will understand! 
0

ジャークライアントを作成するために、wsimportのか、Axis2のようなサードパーティのライブラリを使用してみてください、このクライアントがあなたを変換します:それはあなただけの単純な文字列置換を使用して文字列パラメータでこれを行う場合に役立つはずあなたの状況では 豆を整形式のXMLリクエストに簡単に組み込むことができます。 wsimportの使用

構築物クライアント:開始前

を、あなたは$ JDK/binフォルダにwsimportのツールを見つけることができます。

wsimport -keep -verbose https://www.url.com/xxx/xxx.asmx?wsdl 


のAxis2を使用してクライアントを構築します。 siteから
例:FYI

The short story:

  1. Download and unpack the Apache Axis2 Standard Distribution, if you have not done it already.
  2. Create the client stub with the following command (Assuming that you have Axis2UserGuide.wsdl file on your current working directory):

%AXIS2_HOME%\bin\WSDL2Java -uri Axis2UserGuide.wsdl -p org.apache.axis2.axis2userguide -d adb -s

  1. Create the client (for example, Client.java), a Java application that uses the generated stub, and save it in the org/apache/axis2/axis2userguide directory.

  2. Build the client by typing: ant jar.client.

  3. Assuming you have a corresponding service, run the client by adding the generated Axis2UserGuideService-test-client.jar file located in build/lib to the classpath and type: java org.apache.axis2.axis2userguide.Client

関連する問題