Java 如何修复无SOAPAction标题!错误

Java 如何修复无SOAPAction标题!错误,java,web-services,soap,wsdl,axis,Java,Web Services,Soap,Wsdl,Axis,请在下面找到我用来调用soap端点的html soap客户端代码 我的soap Web服务作为axis项目部署在tomcat中 请查找以下客户代码 <html> <head> <title>SOAP JavaScript Client Test</title> <script type="text/javascript"> function soap() { var xmlhttp

请在下面找到我用来调用soap端点的html soap客户端代码 我的soap Web服务作为axis项目部署在tomcat中

请查找以下客户代码

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://localhost:9090/SMSSoapInterface/services/smsxmlpushservicewsSoap11', true);

            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope ' + 
                    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                    'xmlns:urn="urn:mm7pushinterface' +
                    'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soapenv:Body>' +
                            '<urn:SubmitReq>' +
                            '<urn:MM7Version>5.3.0</urn:MM7Version>' +
                            '<urn:SenderIdentification>' +
                            '<urn:VASPID>1234</urn:VASPID>'+
                            '<urn:VASID>12345</urn:VASID>'+
                            '<urn:CampaignName>SOAP Campaign</urn:CampaignName>'+
                            '<urn:CampaignDesc>test</urn:CampaignDesc>'+
                            '<urn:MsgCategory>1</urn:MsgCategory>'+
                            '<urn:SenderAddress>'+
                            '<urn:RFC2822Address >1244</urn:RFC2822Address>'+
                            '<urn:Number>919901251515</urn:Number>'+
                            '<urn:ShortCode >1234</urn:ShortCode>'+
                            '</urn:SenderAddress>'+
                            '</urn:SenderIdentification>'+
                            '<urn:Recipients>'+
                            '<urn:To>'+
                            '<urn:RFC2822Address >6789</urn:RFC2822Address>'+
                            '<urn:Number >919901251516</urn:Number>'+
                            '<urn:ShortCode >7896</urn:ShortCode>'+
                            '</urn:To>'+
                            '</urn:Recipients>'+
                            '</urn:Recipients>'+
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert('done. use firebug/console to see network response');
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.setRequestHeader('SOAPAction', "");
            xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Authorization');
            xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'POST');
            xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
            xmlhttp.setRequestHeader('username', 'ecpDemoUser');
            xmlhttp.setRequestHeader('password', 'ecpDemo');
            xmlhttp.setRequestHeader('SOAPAction', "");
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
</html> <!-- typo -->
下面是wsdl中存在的soap操作

<soap:operation soapAction=""/>

请告诉我如何解决此问题?

请参阅:

SOAPAction HTTP请求标头字段可用于指示 SOAP HTTP请求的目的。该值是一个URI,用于标识 意图SOAP对数据的格式或特殊性没有任何限制 URI或它是可解析的。HTTP客户端必须使用此标头 发出SOAP HTTP请求时的字段。 SOAPAction标头字段的存在和内容可由 适当过滤SOAP请求的服务器(如防火墙) HTTP中的消息。空字符串(“”)的标题字段值表示 SOAP消息的意图由HTTP提供 请求URI。无值表示没有意图指示 这条消息的一部分

您正在使用需要soap操作的

从技术上讲,如果我们没有找到这个标题,我们可能会出错。 SOAP HTTP绑定中需要它

代码:

private String More ...getSoapAction(HttpServletRequest req) throws AxisFault {

String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction == null) {
    String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
    if(contentType != null) {
        int index = contentType.indexOf("action");
        if(index != -1){
            soapAction = contentType.substring(index + 7);
        }
    }
}


您应该拥有SOAPAction,然后将其发送为空。这已添加到客户端代码requestHeader中。请参阅上面附加的客户端代码xmlHTTP.setRequestHeader('SOAPAction','')?它是空的。我的wsdl soapAction是空的,因此我将它作为空字符串发送。没有为soap操作定义名称
private String More ...getSoapAction(HttpServletRequest req) throws AxisFault {

String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction == null) {
    String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
    if(contentType != null) {
        int index = contentType.indexOf("action");
        if(index != -1){
            soapAction = contentType.substring(index + 7);
        }
    }
}
   if (soapAction == null) {
        AxisFault af = new AxisFault("Client.NoSOAPAction",
                                     Messages.getMessage("noHeader00",
                "SOAPAction"),
                                     null, null);