在Eclipse中创建Web服务并远程访问它VIA WAMP

时间:2014-12-15 06:07:01

标签: java eclipse web-services wsdl wampserver

我正在尝试将在Eclipse中制作的Web服务放在我的WAMP服务器上。我在Eclipse中获取生成的WSDL文件,并将WSDL文件放在我的WAMP服务器上的www文件夹中。我需要远程访问这个Web服务,但是当我从远程计算机创建客户端时(在我的网站上从WSDL导入生成的文件之后),当我尝试运行它时,它表示连接被拒绝。

以下是错误代码:

Exception in thread "main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.ConnectException: Connection refused
 faultActor: 
 faultNode: 
 faultDetail: 
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    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 DefaultNamespace.WebserviceSoapBindingStub.echo(WebserviceSoapBindingStub.java:106)
    at DefaultNamespace.message.main(message.java:18)

    {http://xml.apache.org/axis/}hostname:Shadow.local

java.net.ConnectException: Connection refused
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    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 DefaultNamespace.WebserviceSoapBindingStub.echo(WebserviceSoapBindingStub.java:106)
    at DefaultNamespace.message.main(message.java:18)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    ... 11 more

它在Eclipse中使用Apache Tomcat 8.0(我的WAMP服务器运行Apache 2.4.9),但我不知道为什么我拒绝连接。我打开了端口80和端口8080

这也是我做的客户: *注意:Echo应该返回你放入的内容。

package DefaultNamespace;
import java.util.*;
import java.io.*;

import javax.xml.rpc.ServiceException;
public class message {
    public static void main(String[] args) throws IOException
    {
        Scanner in = new Scanner(System.in);

        System.out.println("Enter a word: ");
        String a = in.next();

        WebserviceServiceLocator locator = new WebserviceServiceLocator();
        WebserviceSoapBindingStub stub;
        try {
            stub = (WebserviceSoapBindingStub)locator.getwebservice();
            System.out.println(stub.echo(a));
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
}

如果我无法通过WAMP服务器远程访问我的网络服务,那我该怎么办? 感谢

1 个答案:

答案 0 :(得分:0)

WAMPServer被配置为开发人员工具,因此为了初学者的安全性,以及那些认为他们比实际知道的更多的人,Apache被配置为仅接受来自运行WAMPSever(Apache)的PC的连接,即{{1 }}

如果您想允许从其他任何地方进行访问,则必须更改localhost以允许从其他地方进行访问。

wampmanager菜单上有一个名为httpd.conf的菜单选项,这将为您更改Put Online,更改

httpd.conf

Require local

并允许从互联网访问,假设您已正确端口转发路由器。

然而,在WAMPServer的vanilla安装上这是危险的,因为它允许访问一切,包括 phpMyAdmin ,基本上赠送皇冠上的珠宝

更安全的解决方案是手动更改Require all granted 文件并仅允许您允许的IP地址,如下所示: -

查看httpd.conf开始httpd.conf

的部分
<Directory "c:/wamp/www/">

或者甚至可能更好的是指定允许连接的主机。

Require local
Require ip w.x.y.z

当然,更好的解决方案是为您的网站创建虚拟主机,这样您就可以将常规访问限制为Require local Require host example.org ,但允许访问此测试网站以访问特定的IP或域。请参阅此帖子了解help creating Virtual Hosts