简体   繁体   English

SOAP JAVA WSDL - 在请求中添加一个值 header

[英]SOAP JAVA WSDL - Add a value in the request header

I have a problem with a request to a SOAP service, I generated the client ( SWDL ) with JAVA and at the moment of making the request it returns an error message: " org.apache.axis.AxisFault: THE SERVICE REQUIRES API KEY ".我在请求SOAP服务时遇到问题,我使用JAVA生成了客户端 ( SWDL ),在发出请求时它返回一条错误消息:“ org.apache.axis.AxisFault: THE SERVICE REQUIRES API KEY ” .

How can I add a token to the header in the following code?如何在以下代码中向 header 添加令牌?

ServiceImplSynchronization service = new ServiceSynchronizationLocator();
ServiceSynchronization ws = new ServiceSynchronizationSoapBindingStub(new URL(service.getServiceFacturacionSynchronizationPortAddress()), service);
ws.verifyCommunication();

Result:结果:

org.apache.axis.AxisFault: THE SERVICE REQUIRES API KEY" 

I solved my problem by overwriting the method in my service locator.我通过覆盖服务定位器中的方法解决了我的问题。

@Override
public Call createCall() throws ServiceException {
_call = new org.apache.axis.client.Call(this) {

    @Override
    public void setRequestMessage(Message msg) {
        super.setRequestMessage(msg);

        MimeHeaders mimeHeaders = msg.getMimeHeaders();
        mimeHeaders.addHeader("headerName", Value);


    }

};

return _call;
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM