程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Soap服务的响应中获取空值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在Soap服务的响应中获取空值?

开发过程中遇到在Soap服务的响应中获取空值的问题如何解决?下面主要结合日常开发的经验,给出你关于在Soap服务的响应中获取空值的解决方法建议,希望对你解决在Soap服务的响应中获取空值有所启发或帮助;

最后,我在我的应用程序中发现我的错误,即我的请求和响应pojo不正确。 我的回应是这样的

@XmlAccessorType(XmlAccesstype.FIELD)
@XmlRootElement(name = "CardupdateResponse",namespace="http://www.corecard.com/PrepaID")
public class FVCardupdateResponse {

    @XmlElement(name="CARDupdatE_RET", namespace="http://www.corecard.com/PrepaID")
    private CARDupdatE_RET response;
    //Getters and setters

    public static class CARDupdatE_RET{

        @XmlElement(name = "ACCOUNTnumbER", namespace="http://www.corecard.com/PrepaID")
        private String Accountnumber;

        @XmlElement(name = "ResCode", namespace="http://www.corecard.com/PrepaID")
        private String ResCode;

        @XmlElement(name = "ResErrorCode", namespace="http://www.corecard.com/PrepaID")
        private String ResErrorCode;

        @XmlElement(name = "ResErrorMsg", namespace="http://www.corecard.com/PrepaID")
        private String ResErrorMsg;

        //Getters and Setters
    }
}

解决方法

我想打电话给肥皂服务。我没有得到任何异常,但响应包含空值。但是服务至少返回错误消息。请找到或指导任何解决方案。

@Component("createCardserviceImpl")
public class CreateCardserviceImpl implements CreateCardservice {

    private static final ObjectFactory WS_CLIENT_FACTORY = new ObjectFactory();

    private WebserviCETemplate webserviCETemplate;

    @Autowired
    public void YourserviceClient(WebserviCETemplate webserviCETemplatE) {
        this.webserviCETemplate = webserviCETemplate;
    }
    @Override
    public FVCardupdateResponse createupdateCardrequest(FVCardupdaterequest fvCardupdaterequest) {
        FVCardupdateResponse fvCardupdateResponse=new FVCardupdateResponse();
        try{
        FVCardupdaterequest request = WS_CLIENT_FACTORY.createFVCardupdaterequest();

        request=fvCardupdaterequest;
        SoapActionCallBACk actionCallBACk = new SoapActionCallBACk("https://www.sampleservice/Selfservice.asmx") {
            public void doWithmessage(Webservicemessage msg) {
                Soapmessage smsg = (SoapmessagE)msg;                
                SoapHeader soapHeader = smsg.getSoapHeader();

                try{
                    Stringsource headersource = new Stringsource("<UserCredentials xmlns='http://www.corecard.com/Prepaid'>\n" +
                            "<userid>"+"srihari"+"</userid>\n" +
                            "<password>"+"srihari123"+"</password>\n" +
                            "</UserCredentials>");
                    Transformer transformer = TransformerFactory.newInstance().newTransformer();
                    transformer.transform(headersource,soapHeader.getResult());

                    smsg.setSoapAction("http://www.sampleservice/Cardupdate");
                }catch(Exception E)
                {
                    e.printStackTrace();
                }
            }
        };
        fvCardupdateResponse = (FVCardupdateResponsE) webserviCETemplate.marshalSendAndReceive("https://www.sampleservice/Selfservice.asmx",request,actionCallBACk);

        System.out.println("source "+fvCardupdateResponsE);

        }catch (SoapFaultClientexception E) {

            System.out.println("fault code "+e.getFaultCode());
            System.out.println("fault String "+e.getFaultStringOrReason());
            System.out.println("stack trace "+e.fillInStackTrace().getLocalizedmessage());
            e.printStackTrace();
        } catch (WebserviceIOException wE) {
            System.out.println("In web service IO Exception "+we.getRootCause());
            we.printStackTrace();
        } catch (Exception E) {
            e.printStackTrace();
        }

        return fvCardupdateResponse;
    }

}

这是我的Objec tFactory类

@XmlRegistry
public class ObjectFactory {

    public ObjectFactory() {
    }

    public FVCardupdaterequest createFVCardupdaterequest() {

        return new FVCardupdaterequest();
    }

    public FVCardupdateResponse createFVCardupdateResponse()
    {
        return new FVCardupdateResponse();
    }
}

这是我的要求课

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CARDupdatE",propOrder={"CLIENTID","CARDnumbER","FIRSTNAME"})

@XmlRootElement(name = "CARDupdatE")
public class FVCardupdaterequest {

    @XmlElement(name = "CLIENTID")
    private String CLIENTID;

    @XmlElement(name = "CARDnumbER")
    private String CARDnumbER;
    //Other  setters and getters
}

这是我的回应课

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CardupdateResponse",propOrder={"CARDupdatE_RET"})
@XmlRootElement(name = "CardupdateResponse",namespace="http://www.sampleurl.com/Prepaid")
public class FVCardupdateResponse {

    @XmlElement(name="CARDupdatE_RET")
    private CARDupdatE_RET  CARDupdatE_RET; 
   //Setters and getters
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CARDupdatE_RET",propOrder = {
    "ResErrorMsg","ResErrorCode","ResCode","Accountnumber"
})

    public class CARDupdatE_RET {

        @XmlElement(name = "Accountnumber")
        private String Accountnumber;

        @XmlElement(name = "ResCode")
        private String ResCode;

        @XmlElement(name = "ResErrorCode")
        private String ResErrorCode;

        @XmlElement(name = "ResErrorMsg")
        private String ResErrorMsg;
    }

这是我的示例xml响应:

<?xml version="1.0" encoding="UTF-8"?>
<CardupdateResponse xmlns="http://www.sampleurl.com/Prepaid">
    <CARDupdatE_RET>
        <ResErrorMsg>Card updated successfully</ResErrorMsg>
        <ResErrorCode>Msgcu01</ResErrorCode>
        <ResCode>1</ResCode>
        <ACCOUNTnumbER>2000000003918246</ACCOUNTnumbER>
    </CARDupdatE_RET>
</CardupdateResponse>

大佬总结

以上是大佬教程为你收集整理的在Soap服务的响应中获取空值全部内容,希望文章能够帮你解决在Soap服务的响应中获取空值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。