java调用c# webservice错误记录及解决 server.userexception java.lang.NullPointerException 解

转自http://blog.csdn.net/xgx1985xgx/article/details/6257368

最近在弄一个java调用c#所写的webservice的程序(我使用的是axis1.4),在测试中用c#写了一个很简单的webservice,然后在myeclipse中采用以下代码调用

view plain
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import org.w3c.dom.*;
/**
* @author xiegx E-mail:544890379@163.com
* @version 创建时间:Mar 10, 2011 5:37:09 PM
* 类说明 测试调用webservice
*/
public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
// 指出service所在URL
String endpoint = "http://localhost:2339/WebSite1/Service.asmx";
// 创建一个服务(service)调用(call)
Service service = new Service();
Call call = (Call)service.createCall();// 通过service创建call对象
// 设置service所在URL
call.setTargetEndpointAddress(new java.net.URL(endpoint));
//设置要调用的方法
call.setOperationName( new QName( "http://www.luculent.net/T","StartService" ));
//设置该方法需要的参数
call.addParameter( "serviceName" , org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
//设置方法返回值的类型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
//调用该方法
call.setSOAPActionURI("http://www.luculent.net/StartService");
String ret = (String) call.invoke(new Object[] { new String("MSSQLSERVER") });

/*// 方法名(processService)与MyService.java方法名保持一致
call.setOperationName("StartService");
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
// Object 数组封装了参数,参数为"This is Test!",调用processService(String arg)
String ret = (String) call.invoke(new Object[] { new String("MSSQLSERVER") });*/
System.out.println(ret);
}catch(Exception ex){
ex.printStackTrace();
System.out.println(ex.toString());
}

}

}

在java中调用c#中StartService的方法,在myeclipse中一切正常,得到了正确的返回结果

然后将上述程序放到jsp文件中,部署到weblogic8.1中运行,结果报以下错误



AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.lang.NullPointerException
at org.apache.axis.message.MessageElement.addTextNode(MessageElement.jav
a:1396)
at org.apache.axis.message.SOAPHandler.addTextNode(SOAPHandler.java:148)

at org.apache.axis.message.SOAPHandler.endElement(SOAPHandler.java:112)
at org.apache.axis.encoding.DeserializationContext.endElement(Deserializ
ationContext.java:1087)
at weblogic.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractS
AXParser.java:585)
at weblogic.apache.xerces.impl.XMLNamespaceBinder.handleEndElement(XMLNa
mespaceBinder.java:898)
at weblogic.apache.xerces.impl.XMLNamespaceBinder.endElement(XMLNamespac
eBinder.java:644)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndEle
ment(XMLDocumentFragmentScannerImpl.java:1008)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentCo
ntentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1469)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocume
nt(XMLDocumentFragmentScannerImpl.java:329)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguratio
n.java:525)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguratio
n.java:581)
at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXPar
ser.java:1175)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:135)

at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:138)

at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at org.apache.axis.encoding.DeserializationContext.parse(Deserialization
Context.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnders
tandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at jsp_servlet.__webservice.stest(__webservice.java:73)
at jsp_servlet.__webservice._jspService(__webservice.java:188)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:446)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

{http://xml.apache.org/axis/}hostname:PC-201004012019

java.lang.NullPointerException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:216)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at jsp_servlet.__webservice.stest(__webservice.java:73)
at jsp_servlet.__webservice._jspService(__webservice.java:188)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)





上述问题的原因是axis1.4和weblogic8.1有冲突,weblogic 本身携带的webservice.jar使用的旧的javax.xml.soap.*,而不是像axis使用J2EE1.4新的版本。解决方案是在应用WEB-INF/weblogic.xml(若应用中没有weblogic.xml,则可以在bea/weblogic81/samples/server/examples/build/examplesWebApp/WEB-INF中拷贝)在文件中加入如下红色配置:

<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

修改后重启weblogic,一切正常,问题解决!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值