Web 服务的简单 Java 客户端代码 - 与 QName 有关系吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/201476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple java client code for Web Service - something to do with QName?
提问by Vidar
I am getting the following error when I get to the line that invokes a REALLY BASIC web service I have running on Tomcat/Axis.
当我到达调用我在 Tomcat/Axis 上运行的 REALLY BASIC Web 服务的行时,出现以下错误。
Element or attribute do not match QName production: QName::=(NCName':')?NCName
Have I got something wrong with QName?- I can't even find any useful information about it.
QName 有问题吗? - 我什至找不到任何有用的信息。
My client code is below:
我的客户端代码如下:
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestClient {
public static void main(String [] args)
{
try{
String endpoint = "http://localhost:8080/TestWebService/services/DoesMagic";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( new QName("http://testPackage.fc.com/, doBasicStuff") );
String ret = (String) call.invoke( new Object[] {"some kind of message"} );
System.out.println(ret);
}catch(Exception e){
System.err.println(e.toString());
}
}
}
My web serivce code is really basic - just a simple class that returns your input string with a bit of concat text:
我的网络服务代码非常基础 - 只是一个简单的类,它返回带有一些 concat 文本的输入字符串:
public String doBasicStuff(String message)
{
return "This is your message: " + message;
}
采纳答案by Martin Probst
As the exception says, you call the QName constructor incorrectly:
正如异常所说,您错误地调用了 QName 构造函数:
new QName("http://testPackage.fc.com/, doBasicStuff")
is incorrect. I think you have to pass two strings, one containing the namespace, one the localname. The documentation will typically contain a description on how to use that class.
是不正确的。我认为您必须传递两个字符串,一个包含命名空间,一个包含本地名称。该文档通常会包含有关如何使用该类的说明。
回答by Rich Kroll
Could it be a typo in your QName?:
可能是您的 QName 中的错字?:
new QName("http://testPackage.fc.com/", "doBasicStuff")
instead of:
代替:
new QName("http://testPackage.fc.com/, doBasicStuff")
回答by Don G.
You should use one of these:
您应该使用以下之一:
public QName(String localPart) or
public QName(final String namespaceURI, final String localPart)
but new QName("http://testPackage.fc.com/, doBasicStuff") is wrong, since both values are in the same string ".., .."
但是 new QName(" http://testPackage.fc.com/, doBasicStuff") 是错误的,因为两个值都在同一个字符串 ".., .." 中
Regards
问候
回答by Ali Hashemi
new QName("soapenc:string", "doBasicStuff")
new QName("soapenc:string", "doBasicStuff")
回答by mohamed
Just type the name of metod that have to on your case it would be
call.setOperationName("doBasicStuff");
只需输入必须在您的情况下使用的方法名称即可
call.setOperationName("doBasicStuff");