1

次のコードからSOAPリクエストオブジェクトを作成する必要があるプロジェクトに取り組んでいます:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mod="http://www.tmforum.org/xml/tip/model" xmlns:prob="http://www.tmforum.org/xml/tip/cbe/problem" xmlns:geo="http://www.tmforum.org/xml/tip/cbe/loc/geo" xmlns:loc="http://www.tmforum.org/xml/tip/cbe/loc" xmlns:tt="http://www.tmforum.org/xml/tip/cbe/tt" xmlns:ent="http://www.tmforum.org/xml/tip/internal/entity" xmlns:ext="http://www.tmforum.org/xml/tip/cbe/problem/extensions">
   <soapenv:Header/>
   <soapenv:Body>
      <mod:retrieveProblemRequest>
         <!--Optional:-->
         <mod:customerProblem>
            <!--Optional:-->
            <prob:problemId>0005004426</prob:problemId>

         </mod:customerProblem>
      </mod:retrieveProblemRequest>
   </soapenv:Body>
</soapenv:Envelope>

KSOAP2 を使用してリクエスト オブジェクトを作成していますが、名前空間の割り当てに問題があるため、送信されるリクエストは常に正しくありません。

この SoapRequest を Android の SoapObject に変換するコードを教えてください。

編集:私のコードは次のとおりです:

private static String SOAP_ACTION1 = "/BusinessServices/Inbound/TIP_R4GCanonicalModel_model_problemservicev1dot3-service0.serviceagent/ProblemServiceV1dot3Endpoint0/retrieveProblem";
    private static String REQUEST_TARGET_NAMESAPCE="http://xmlns.example.com/1362214927265/";
    private static String TARGET_NAMESPACE_MOD = "http://www.tmforum.org/xml/tip/model/";
    private static String NAMESPACE_PROB="http://www.tmforum.org/xml/tip/cbe/problem/";
    private static String METHOD_NAME = "retrieveProblem";
    private static String URL = "http://10.128.28.44:10005/BusinessServices/Inbound/ProblemService_proxy.serviceagent/ProblemServiceV1dot3Endpoint0";
public static String LOG_TAG = "SOAPRequestResponseActivity";


    @Override
    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            btnFar = (Button) findViewById(R.id.btnFar);
        btnFar.setOnClickListener(new View.OnClickListener()

        {
            @Override
            public void onClick(View v)

            {

                // Initialize soap request + add parameters

                SoapObject request = new SoapObject(REQUEST_TARGET_NAMESAPCE,METHOD_NAME);

                SoapObject retrieveInfo=new SoapObject(TARGET_NAMESPACE_MOD,"retrieveProblemRequest");

                SoapObject customerObject=new SoapObject(TARGET_NAMESPACE_MOD, "customerProblem");

                PropertyInfo info=new PropertyInfo();
                info.setNamespace(NAMESPACE_PROB);
                info.setName("problemId");
                info.setValue("0005004426");

                customerObject.addProperty(info);
                retrieveInfo.addSoapObject(customerObject);
                request.addSoapObject(retrieveInfo);

   Log.i(LOG_TAG, "===Request soap object after params=="
                        + request.toString());

                // Declare the version of the SOAP request

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);


                envelope.implicitTypes=true;
                envelope.setOutputSoapObject(request);

                try {

                    HttpTransportSE androidHttpTransport = new HttpTransportSE(
                            URL);



                    ArrayList<HeaderProperty> headerProperty = new ArrayList<HeaderProperty>();

                    headerProperty.add(new HeaderProperty("SOAPAction", "/BusinessServices/Inbound/TIP_R4GCanonicalModel_model_problemservicev1dot3-service0.serviceagent/ProblemServiceV1dot3Endpoint0/retrieveProblem"));

                    androidHttpTransport.call(SOAP_ACTION1, envelope,headerProperty);

Call メソッドが呼び出されるとすぐに、エラー コード 500 で Exception HttpRequestFailed がスローされます。

適切な解決策を教えてください。

4

1 に答える 1

1

ksoap2-androidという名前のライブラリに出会いました。これは非常に役立ちます。これを試すことができます。Web メソッドを呼び出すために使用したクラス ファイルは次のとおりです。

 public class CallSOAP {

private String SOAP_ACTION="your action url";
private String OPERATION_NAME="";//The web method OR web service you are going to call
private final String WSDL_TARGET_NAMESPACE=SOAP_ACTION;
private  final String SOAP_ADDRESS=Configuration.WEB_SERVICE_URL;//ip-address of serever where you host your service 
private Exception exception;
private String ErrorMsg="";
private String TERST_URL="" ;
public Object call(String MethodeName,ArrayList<PropertyInfo> Parameters){

  this.OPERATION_NAME=MethodeName;
  SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
 if(Parameters != null && Parameters.size()>0){
   for(PropertyInfo propertyInfo : Parameters){
      request.addProperty(propertyInfo);
 }
}

SoapSerializationEnvelope  envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet= true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport =null;
if(!this.TERST_URL.equals(""))
  httpTransport = new HttpTransportSE(this.TERST_URL);
else
  httpTransport = new HttpTransportSE(SOAP_ADDRESS);
 Object Response =null;
 try{
    httpTransport.call(SOAP_ACTION+OPERATION_NAME, envelope);
    Response=envelope.getResponse();
  }
 catch (SocketTimeoutException ex) {
     this.ErrorMsg="Unable to connect";
      Response=null;
     this.exception=ex;
  }
  catch (IOException ie) {
   this.ErrorMsg="Unable to connect";
  Response=null;
   this.exception=ie;
  }
   catch (Exception e) {
    this.ErrorMsg="Unable to connect";
    Response=null;
    this.exception=e;
 }
      return Response;
   }
}

ASP.NET フレームワークで書かれた Web サービスを使用していたことに注意してください。

envelope.dotNet= true;

参考:このチュートリアルを参照してください

この質問を参照してください

于 2013-04-02T08:41:06.137 に答える