读书人

Web Service高手

发布时间: 2012-08-10 12:19:33 作者: rapoo

求助Web Service高手
我写了一个.net的Web service供java程式调用,有.net自定义对象传递。
自定义Class:
[Serializable]
public class E00900
{
private string _autosend;
public string autoSend
{
get
{
return _autosend;
}
set
{
_autosend = value;
}
}
......
}

web service 方法:
[WebMethod]
[SoapRpcMethod(Action= "http://tempuri.org/Test1", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
public E00900 Test1(string str)
{
E00900 e900 = new E00900();
e900.autoSend = str;
return e900;

}

[SoapRpcMethod(Action= "http://tempuri.org/Test2", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
public string Test2(E00900 e900)
{
return e900.autoSend;
}

Test1方法是传递一个字符串返回E00900对象,Test2方法传递E00900对象返回字符串

用Java程式调用Test1方法是OK的,可以正常返回E00900对象,但是调用Test2方法就出问题了
Java程式Call Test2方法:

String namespace = "http://tempuri.org/";// xmlns

String methodName = "Test2";//方法名

String soapActionURI = "http://tempuri.org/Test2"; //

Service service = new Service();

Call call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));

QName qn = new QName("E00900");



call.registerTypeMapping(E00900.class, qn,

new org.apache.axis.encoding.ser.BeanSerializerFactory(E00900.class, qn),

new org.apache.axis.encoding.ser.BeanDeserializerFactory(E00900.class, qn));



call.setOperationName(new QName(namespace, methodName));

call.setUseSOAPAction(true);

call.setSOAPActionURI(soapActionURI);//设置SOAPAction


E00900 e901 = new E00900();

e901.setAutoSend("123");


call.addParameter("e900", qn , ParameterMode.IN);

call.setReturnType(XMLType.XSD_STRING);

String ret = (String) call.invoke( new Object[] { e901 } );

System.out.println( "result is " + ret + ".");


提示错误讯息"伺服器法理要求。 --> 物件型不可以成目型。"
请问这个是.Net Server端的问题还是Java Client端的问题?应该如何解决?




[解决办法]
你写个net的客户端,调用同样的函数,抓取soapmessage。
再让java客户端的的程序员把他发出的soapmessage给你,比较下应该就知道问题在哪里了。
[解决办法]
可以这么调用吗?
不是有wcf可以跨语言调用,写wcf吧?一样的
[解决办法]
既然你有怀疑了就去测试呀。照着思路去重新做一遍,确认一下是Server配置好了没有,如果配置好了在在JAVA里面测试能不能正确调用。或者设个断点单步调试下,看看到底是什么原因。祝你好运LZ!
[解决办法]
跨语言间,不可以这样调用.
你用JAVA写的E00900类 != .NET写的E00900类

老老实实的使用基础数据类型吧.

既然是WebService,跨语言间的调用与传递就应该严格的使用XML,而不要去使用自定义类,即使要用,也应该序列化成XML进行传递,而不能直接去new XXX自定义类.这样就失去WebService的意义了.
------解决方案--------------------


同意8楼的说法

读书人网 >asp.net

热点推荐