KSOAP和Web服务器通信(PropertyInfo)

时间:2013-03-18 10:33:12

标签: android weblogic ksoap propertyinfo

所以我正在开发一个应该连接到Web服务的Android应用程序。这种连接工作正常。我使用一个返回“Hello Christian”的简单方法测试了它。这在应用程序中显示正确。如果我尝试使用参数(name)执行此操作,则返回“Hello null”。

从技术上讲,我正在使用Android 4.2.2和KSOAP 2.6.5。 Web服务在Oracle WebLogic v12上运行。关注我的源代码:

private final String NAMESPACE_Local = "http://test.com/";
private final String URL_Local = "http://168.185.226.69:7001/neuesProjekt/neuerWebServiceService";
private final String SOAP_ACTION_Local = "Hello_Action_Name";
    private final String METHOD_NAME_Local = "helloname";

    private final String URL_Local = "http://168.185.226.21:7001/myTest/myTestWebServiceService";
  private final String SOAP_ACTION_Local = "Hello_Action_Extend";
   private final String METHOD_NAME_Local = "hello_extend";

        public void LocalServer(View view)
        {
            TextView text = (TextView) findViewById(R.id.update_text);

            SoapObject request = new SoapObject(NAMESPACE_Local, METHOD_NAME_Local);
    //      request.addProperty("name", "Christian");

    //      String name = "Christian";
    //      
    //      PropertyInfo nameProp =new PropertyInfo();
    //        nameProp.name = "name";
    //        nameProp.type = String.class;
    //        nameProp.namespace = NAMESPACE_Local;
    //        nameProp.setValue(name);
    //        request.addProperty(nameProp);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Local);

            try {
                androidHttpTransport.call(SOAP_ACTION_Local, envelope);
                SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
                Log.i("myApp", response.toString());


            text.setText(response.toString());

        } catch (Exception e) {
            Toast.makeText(this,"Device or service offline",Toast.LENGTH_LONG).show();
        }
    }

我试过以两种方式添加propertyInfo。首先使用简单的request.addProperty以及创建PropertyInfo并在之后添加它的漫长道路。两种方式都不起作用。 然而,当我尝试使用某个教程中的服务器(例如摄氏度到华氏度)时,它会起作用并返回正确的答案。

这是来自网络服务器的'代码':

package com.test;

import javax.jws.*;

@WebService
public class myTestWebService {

    @WebMethod(action="Hello_Action")
    public String hello() {
        return "hello";
    }

    @WebMethod(action="Hello_Action_Extend")
    public String hello_extend(String name)
    {
        return "hello "+name;
    }
}

遵循WSDL文件以防万一它有助于解决我的问题:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.6hudson-86  svn-revision#12773. -->
<definitions targetNamespace="http://test.com/" name="myTestWebServiceService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://test.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://test.com/" schemaLocation="myTestWebServiceService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="hello">
    <part name="parameters" element="tns:hello"/>
  </message>
  <message name="helloResponse">
    <part name="parameters" element="tns:helloResponse"/>
  </message>
  <portType name="myTestWebService">
    <operation name="hello">
      <input wsam:Action="Hello_Action" message="tns:hello"/>
      <output wsam:Action="http://test.com/myTestWebService/helloResponse" message="tns:helloResponse"/>
    </operation>
  </portType>
  <binding name="myTestWebServicePortBinding" type="tns:myTestWebService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="hello">
      <soap:operation soapAction="Hello_Action"/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="myTestWebServiceService">
    <port name="myTestWebServicePort" binding="tns:myTestWebServicePortBinding">
      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
    </port>
  </service>
</definitions>

所以我希望你们中的一个可以帮助我,因为我很无能为力。 亲切的问候, 基督教

1 个答案:

答案 0 :(得分:0)

我并不擅长此事,事实上本周只有我的网络服务才能运作。

尝试

envelope.dotNet = true;
String name = "Christian";
request.addProperty("name", name);

或者

envelope.dotNet = true;
PropertyInfo nameProp =new PropertyInfo();
nameProp.setName("name");
nameProp.setType(String.class);
nameProp.setValue(name);
request.addProperty(nameProp);

我希望这能为你解决这个问题