如何从xml请求中删除xmlns =""

Mah*_*leh 5 java soap web-services cxf jaxb

我正在使用CXF 3.0.8来调用Web服务:

@WebService(targetNamespace = "http://tempuri.org/", name = "INotificationGateway")
@XmlSeeAlso({ObjectFactory.class, com.microsoft.schemas._2003._10.serialization.ObjectFactory.class, org.datacontract.schemas._2004._07.notificationsgateway.ObjectFactory.class, com.microsoft.schemas._2003._10.serialization.arrays.ObjectFactory.class})
public interface INotificationGateway {

    @WebResult(name = "SendSMSResult", targetNamespace = "http://tempuri.org/")
    @Action(input = "http://tempuri.org/INotificationGateway/SendSMS", output = "http://tempuri.org/INotificationGateway/SendSMSResponse", fault = {@FaultAction(className = INotificationGatewaySendSMSEAICustomErrorFaultFaultMessage.class, value = "http://tempuri.org/INotificationGateway/SendSMSEAICustomErrorFault")})
    @RequestWrapper(localName = "SendSMS", targetNamespace = "http://tempuri.org/", className = "org.tempuri.SendSMS")
    @WebMethod(operationName = "SendSMS", action = "http://tempuri.org/INotificationGateway/SendSMS")
    @ResponseWrapper(localName = "SendSMSResponse", targetNamespace = "http://tempuri.org/", className = "org.tempuri.SendSMSResponse")
    public org.datacontract.schemas._2004._07.notificationsgateway.NotificationResponse sendSMS(
        @WebParam(name = "SendSMSNotificationRequest")
        org.datacontract.schemas._2004._07.notificationsgateway.SendSMSNotificationRequest sendSMSNotificationRequest
    ) throws INotificationGatewaySendSMSEAICustomErrorFaultFaultMessage;

}
Run Code Online (Sandbox Code Playgroud)

我在服务请求中发送的对象是:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SendSMSNotificationRequest", propOrder = { "isArabic", "mobileNo", "refrenceId", "templateCode",
        "templateValues" })
public class SendSMSNotificationRequest {

    @XmlElementRef(name = "IsArabic", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false)
    protected JAXBElement<Boolean> isArabic;
    @XmlElementRef(name = "MobileNo", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false)
    protected JAXBElement<String> mobileNo;
    @XmlElementRef(name = "RefrenceId", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false)
    protected JAXBElement<String> refrenceId;
    @XmlElementRef(name = "TemplateCode", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false)
    protected JAXBElement<String> templateCode;
    @XmlElementRef(name = "TemplateValues", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false)
    protected JAXBElement<ArrayOfstring> templateValues;
Run Code Online (Sandbox Code Playgroud)

当我调用该服务时,soap body按如下方式发送,前缀为错误的xmlns ="":

<MobileNo xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">0000000000</MobileNo>
<RefrenceId xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">123</RefrenceId>
<TemplateCode xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">123</TemplateCode>
Run Code Online (Sandbox Code Playgroud)

如果我删除xmlns =""并在sopui中使用此soap请求,该服务工作正常,所以我想知道如何从请求中删除此xmlns ="",我使用的代码如下:

JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(INotificationGateway.class);
factoryBean.setAddress("https://localhost:4431/NotificationsGateway/NotificationGateway.svc");
INotificationGateway port = (INotificationGateway) factoryBean.create();

Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());

HTTPConduit http = (HTTPConduit) client.getConduit();

http.getAuthorization().setUserName("myuser");
http.getAuthorization().setPassword("mypass");
TLSClientParameters tlsCP = new TLSClientParameters();
if (ignoreSSL)
    tlsCP.setTrustManagers(createIgnoredTrustManager());
tlsCP.setDisableCNCheck(true);
http.setTlsClientParameters(tlsCP);

Endpoint cxfEndpoint = client.getEndpoint();

Map<String, Object> outProps = new HashMap<String, Object>();

outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, "myuser");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());

WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
port.sendSMS(sendSMSNotificationRequest);
Run Code Online (Sandbox Code Playgroud)

请告知如何解决这个问题,谢谢.

SAN*_*NN3 -1

我们可以使用拦截器从请求中删除不需要的xmlns="" 。