VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 630|回复: 1

java调用.net的webservice抛SAXNotRecognizedException异常??请高手帮帮忙!!

[复制链接]

1

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-2-5 12:30:01 | 显示全部楼层 |阅读模式
代码:
String endpoint = "http://localhost/WebServiceTest/Service1.asmx";
Service service = new Service();
Call   call   = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://tempuri.org/","HelloWorld"));
call.setReturnType(XMLType.XSD_STRING);
String res = (String) call.invoke( new Object[] {} );
System.out.println( res );

异常:
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/properties/lexical-handler
faultActor:
faultNode:
faultDetail:
        {http://xml.apache.org/axis/}stackTrace: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/properties/lexical-handler
        at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:155)
        at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:241)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
        at org.apache.axis.client.Call.invoke(Call.java:2553)
        at org.apache.axis.client.Call.invoke(Call.java:2248)
        at org.apache.axis.client.Call.invoke(Call.java:2171)
        at org.apache.axis.client.Call.invoke(Call.java:1691)
        at com.dawen.cooperate.TestClient.main(TestClient.java:25)


org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/properties/lexical-handler
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:543)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
        at org.apache.axis.client.Call.invoke(Call.java:2553)
        at org.apache.axis.client.Call.invoke(Call.java:2248)
        at org.apache.axis.client.Call.invoke(Call.java:2171)
        at org.apache.axis.client.Call.invoke(Call.java:1691)
        at com.dawen.cooperate.TestClient.main(TestClient.java:25)
Caused by: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/properties/lexical-handler
        at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:155)
        at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:241)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
        ... 7 more
回复

使用道具 举报

0

主题

6

帖子

6.00

积分

新手上路

Rank: 1

积分
6.00
发表于 2020-3-24 15:45:02 | 显示全部楼层
import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

你用这个看看。

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;

public class AxisWSClient
{
   
    private String   endpoint;
    private String   qName;
    private String   operationName;


    public AxisWSClient(String endpoint, String qName, String operationName)
    {
        this.endpoint = endpoint;
        this.qName = qName;
        this.operationName = operationName;
    }

    public Object getRemoteResult(Object[] inParam, Class outClazz) throws RemoteException
    {
        String endpoint = this.endpoint;
        String qName = this.qName;
        String operationName = this.operationName;

        Call call = null;
      
        //System.out.println("11111111111111");        
        Object[] o = new Object[] {};
      
        try
        {
                Service service = new Service();   
            call = (Call)service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
            call.setOperationName(new QName(qName, operationName));

            if(inParam != null)
                o = inParam;

            if(outClazz != null)
            {
                    String className = outClazz.getName();
                    int i = className.lastIndexOf(".") + 1;
                    className = className.substring(i, className.length());
                   
                QName qn = new QName("urn:" + className, className);
                call.registerTypeMapping(outClazz, qn, new BeanSerializerFactory(outClazz, qn),
                        new BeanDeserializerFactory(outClazz, qn));
            }
        }

        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
        return call.invoke(o);
    }

    public Object getRemoteResult(Class inParamClazz, Class outClazz)
    {
        return null;
    }

    public Object getRemoteResult(Class inParamClazz)
    {
        return null;
    }

    public static void main(String args[])
    {

            /*
             * test string function
             */
        /*AxisWSClient kc = new AxisWSClient("http://127.0.0.1:7001/WebRoot/services/TestWS",
                "services.blackjack.ftyd.com", "testString");

        Object[] o = new Object[]
        { new String("shinhua")};
        
        try
        {
            String  sr = (String)kc.getRemoteResult(o, null);
            System.out.println(sr);
        }        
        catch (RemoteException e)
        {
            e.printStackTrace();
        }*/
           
           
    }
   
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表