不是有效的服务SOAP调用

时间:2014-04-04 02:27:31

标签: java web-services java-ee exception soap

我正在创建我的第一个SOAP服务,我收到的错误不是有效的服务。有人可以帮帮我吗?我正在创建一个假想的皮带店项目。所以我的服务应该是所有尚未发货的产品。现在我只是将它发送到阵列中。一旦服务开始工作,我将以更好的方式修改它。

以下是我的错误

 Exception in thread "main" javax.xml.ws.WebServiceException: {http://service.itmd.iit/}OrdersImplService is not a valid service. Valid services are: {http://util.itmd.iit/}OrdersImplService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:200)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:145)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56)
at javax.xml.ws.Service.create(Service.java:680)
at iit.itmd.client.Client.main(Client.java:19)

以下是我的界面

package iit.itmd.service;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.bind.annotation.XmlRootElement;

@WebService
@SOAPBinding(style=Style.RPC)
@XmlRootElement
public interface Orders {
@WebMethod String[] getNotFulfilled();
}

实现上述接口的My Order Implementation类如下所示

package iit.itmd.util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import iit.itmd.service.Orders;
@XmlType
@WebService(endpointInterface="iit.itmd.service.Orders")
public class OrdersImpl implements Orders{

@Override
@XmlElement
public String[] getNotFulfilled() {
    // TODO Auto-generated method stub
    Connection conn=null;
    Statement statement=null;
    int i=0;
    String selecttableSql="select id,customer_id from orders where  status<>'SHIPPED'";
    String[] result=null;
    try{
    DBConn con=new DBConn();
    conn=con.getConnection();
    statement = conn.createStatement();
    ResultSet rs = statement.executeQuery(selecttableSql);
    System.out.println(rs.getFetchSize());
    while (rs.next()) {

        String orderId = rs.getString("ID");
        String customerId = rs.getString("CUSTOMER_ID");
        result[i]=orderId;
        result[i]= customerId;
        System.out.println("userid : " + orderId);
        System.out.println("username : " + orderId);

    }}
    catch (SQLException e) {

        System.out.println(e.getMessage());

    } finally {

        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

    return result;
}

}

我创建了一个调用SOAP服务的客户端。客户端的代码在

之下
package iit.itmd.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import iit.itmd.domain.*;
import iit.itmd.service.Orders;
public class Client {

public static void main(String[] args) throws MalformedURLException {
    URL url = new URL("http://localhost:9999/BeltStore/getnotshipped");

    //1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
    QName qname = new QName("http://service.itmd.iit/", "OrdersImplService");
    Service service = Service.create(url, qname);
    Orders order = service.getPort(Orders.class);
    System.out.println(order.getNotFulfilled());
}

}

有人可以让我知道我做错了什么吗?感谢。

1 个答案:

答案 0 :(得分:0)

在您的客户端代码中,您为服务指定了命名空间,这是一种很好的做法,但我没有在您的服务代码中看到该命名空间。您的服务必须定义命名空间,这应该与客户端用于指定Web服务方法的命名空间相对应。 E.g。

@WebService(targetNamespace = "http://service.itmd.iit/")