【发布时间】:2015-04-23 22:11:02
【问题描述】:
我正在尝试通过提供 WSDL 的 url 来访问在 WSDL 中定义的 Web 服务。我正在处理的具体案例是 ebay“FindingService”。
解析 WSDL 后,我搜索我正在寻找的服务(例如“FindingService”)。接下来,我希望能够通过某种客户端使用该服务(发送关键字并获取结果)。我环顾四周,找到了以下代码,我尝试修改它以将其用于我的示例。由于我还是 WSDL 的新手,我不确定如何适应它,并且不断收到错误消息:未定义的端口类型:{http://WSDL/}face
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class client{
public static void main(String[] args) throws Exception {
URL url = new URL("http://developer.ebay.com/webservices/finding/latest/findingservice.wsdl");
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://www.ebay.com/marketplace/search/v1/services", "FindingService");
Service service = Service.create(url, qname);
face hello = service.getPort(face.class);
System.out.println(hello.getHelloWorldAsString("test"));
}
}
第二类是:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface face{
@WebMethod String getHelloWorldAsString(String name);
}
第三类是:
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "face")
public class endp implements face{
@Override
public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}
}
如果我能得到一些指导,我将不胜感激。是否可以访问这样的服务,还是我必须使用 ebay API(使用密钥等)?
【问题讨论】:
-
我认为您的 URL 应该指向已部署的服务,而不是 WSDL。 WSDL 应该已用于生成客户端,不应在代码中使用,除非您使用的是动态客户端。
-
这实际上是我想要做的。我希望该程序不仅适用于不同的 wsdl,这就是为什么我试图避免使用 wsdl 生成客户端的原因!有可能吗?
标签: java web-services wsdl jax-ws ebay-api