简体   繁体   English

(JAVA)SOAP WebService错误对象引用未设置为对象的实例

[英](JAVA) SOAP WebService error object reference not set to an instance of an object

i am trying to set up connection to SOAP WebService from Android app but every time i get wried error in my result : object reference not set to an instance of an object java It seems to be error from server --> SOAP Webservice call from Java gives "Object reference not set to an instance of an object" 我试图从Android应用程序建立到SOAP Web服务的连接,但是每次我的结果出错时:对象引用未设置为对象java的实例。这似乎是服务器的错误-> Java的SOAP Web服务调用给出“对象引用未设置为对象的实例”

But when i try it throught web browser with POST request it works fine :) 但是当我通过带有POST请求的Web浏览器尝试它时,它工作正常:)

This service http://ws.cdyne.com/ip2geo/ip2geo.asmx?op=ResolveIP 此服务http://ws.cdyne.com/ip2geo/ip2geo.asmx?op=ResolveIP

private static String NAMESPACE = "http://ws.cdyne.com/";
private static String URL = "http://ws.cdyne.com/ip2geo/ip2geo.asmx";
private static String SOAP_ACTION = "http://ws.cdyne.com/";

public static String invokeHelloWorldWS(String name, String webMethName) {
    String resTxt = null;

    SoapObject request = new SoapObject(NAMESPACE, webMethName);
    PropertyInfo sayHelloPI = new PropertyInfo();
    // Set name
    sayHelloPI.setName("ipAddress");
    // Set Value
    sayHelloPI.setValue("88.212.35.129");
    // Set dataType
    sayHelloPI.setType(String.class);
    // Add the property to request object
    request.addProperty(sayHelloPI);
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;  
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
    try{
        // Invoke web service
        androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);  //webMethName = "ResolveIP"
        // Get the response
        Log.d("a", androidHttpTransport.responseDump);
        //SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        // Assign it to resTxt variable static variable
        //resTxt = response.toString();
    }catch(Exception e){
         //Print error
        e.printStackTrace();
    }
}

I spend lot of time on google but i cant figure right answer why this happend 我在Google上花费了很多时间,但我找不到正确的答案,为什么会这样

// EDIT Finally i get it right ... idk why but when i send second parameter like this (i reuse old property) : //编辑最后我正确了... idk为什么但是当我发送第二个这样的参数时(我重用了旧属性):

sayHelloPI.setName("licenseKey");
sayHelloPI.setValue("some_key");
sayHelloPI.setType(String.class);
request.addProperty(sayHelloPI);

it wasnt working. 它没有工作。 But when i make new Property object it works: 但是当我创建新的Property对象时,它起作用:

PropertyInfo sayHelloPI1 = new PropertyInfo();
sayHelloPI1.setName("licenseKey");
sayHelloPI1.setValue("ds");
sayHelloPI1.setType(String.class);
request.addProperty(sayHelloPI1);

Maybe it help someone next time 也许下次可以帮助别人

This is some code that I have used myself - Hope it will help you: 这是我自己使用的一些代码-希望它对您有所帮助:

        // Initialize soap request + add parameters
        SoapObject request = new SoapObject(getString(R.string.Namespace),
                getString(R.string.Method_Name_GetStudentsByTeam));
        Log.d("GetStudentsByTeamTask", "SOAP request");

        // Use this to add parameters
        request.addProperty("teamId", params[0]);
        Log.d("GetStudentsByTeamTask", "id: " + params[0]);

        // Declare the version of the SOAP request
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        Log.d("GetStudentsByTeamTask",
                "Declared the version of the SOAP request");

        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;
        Log.d("GetStudentsByTeamTask", "Setting som variables");
        try {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(
                    getString(R.string.URL));
            Log.d("GetStudentsByTeamTask", "Instance the HttpTransportSE");

            // this is the actual part that will call the webservice
            androidHttpTransport.call(
                    getString(R.string.Soap_Action_GetStudentsByTeam),
                    envelope);
            Log.d("GetStudentsByTeamTask", "Called the Webservice");

            // Get the SoapResult from the envelope body.
            SoapObject result = (SoapObject) envelope.getResponse();
            Log.d("GetStudentsByTeamTask", "Got the Soapresult");

            if (result != null) {
                // Do something with result
                // success = true;
                Log.d("GetStudentsByTeamTask", "set sucess boolean to true");

                for (int i = 0; i < result.getPropertyCount(); i++) {

                    PropertyInfo pi = new PropertyInfo();
                    result.getPropertyInfo(i, pi);
                    Log.d("GetStudentsByTeamTask",
                            pi.name + " : " + result.getProperty(i));

                    SoapObject obj = (SoapObject) result.getProperty(i);

                    Student student = new Student();

                    student.address = obj.getProperty("Address").toString();

                    student.city = obj.getProperty("City").toString();
                    student.created = DateTime.parse(obj.getProperty(
                            "Created").toString());
                    student.dateOfBirth = DateTime.parse(obj.getProperty(
                            "DateOfBirth").toString());
                    student.email = obj.getProperty("Email").toString();
                    student.firstname = obj.getProperty("FirstName")
                            .toString();
                    student.id = Integer.parseInt(obj.getProperty("ID")
                            .toString());
                    student.imageId = Integer.parseInt(obj.getProperty(
                            "ImageID").toString());
                    // SoapObject lastNameObject = (SoapObject) obj
                    // .getProperty("LastName");
                    //
                    student.lastName = obj.getProperty("LastName")
                            .toString();

                    student.phone = obj.getProperty("Mobile").toString();

                    student.zipcode = obj.getProperty("PostalCode")
                            .toString();
                    student.schoolId = Integer.parseInt(obj
                            .getPropertyAsString("SchoolId"));
                    student.teamId = Integer.parseInt(obj
                            .getPropertyAsString("TeamId"));
                    student.testStarted = Integer.parseInt(obj
                            .getPropertyAsString("TestsStarted"));
                    student.timeStamp = DateTime.parse(obj
                            .getPropertyAsString("TimeStamp"));
                    student.image = getImage(Integer.parseInt(obj
                            .getProperty("ImageID").toString()));

                    if (student.image == null)
                        student.image = BitmapFactory
                                .decodeResource(getResources(),
                                        R.drawable.default_usericon);

                    MyApp.getController().addStudent(student);
                }

            } else {
                // If fails
                // success = false;
                Log.d("GetStudentsByTeamTask", "set login boolean to false");
            }
        } catch (Exception e) {
            Log.d("GetStudentsByTeamTask", "FAILED! " + e.getMessage());
            e.printStackTrace();
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对象引用未设置为 Java 中 SOAP WebService 的对象实例 - Object reference not set to an instance of an object for SOAP WebService in Java Android中的WebService错误。 你调用的对象是空的 - Error with WebService in Android. Object reference not set to an instance of an object java soap webservice xml对象 - java soap webservice xml to object Java - 客户端从服务器收到 SOAP 错误:服务器无法处理请求。 ---&gt; 未将对象引用设置为对象的实例 - Java - Client received SOAP Fault from server: Server was unable to process request. ---> Object reference not set to an instance of an object Spring MVC-获取SOAP响应时,“ IllegalArgumentException:对象引用未设置为对象的实例” - Spring MVC - “IllegalArgumentException: Object reference not set to an instance of an object” when get SOAP response SoapFault-错误代码:“ soap:Server”错误字符串:“服务器无法处理请求。对象引用未设置为对象的实例 - SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request.Object reference not set to an instance of an object 在Java中设置的对象引用 - object reference set in java 对象集包含按值包含对象的对象(非引用)(java 7) - Set of object contains by object with value (not reference) (java 7) 将文件上传到SharePoint时,出现“对象引用未设置为对象实例”错误 - Get 'Object reference not set to an instance of an object' error when upload file to SharePoint 基于对象的Java Web服务 - Java Webservice based on Object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM