2014-04-04 51 views
0

我正在創建我的第一個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(); 
} 

我一個實現了上述接口訂單實現類下面

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()); 
} 

} 

有人請讓我知道我在做什麼錯了嗎?謝謝。

+0

RPC是完全不贊成的,確定你需要使用它嗎? – bmargulies

+0

你好@bmargulies感謝你的回覆。這只是我試用的一個示例應用程序。我想學習SOAP Web服務,這只是一個起點。 – user3331114

+0

然後使用'文檔'而不是'rpc'。 – bmargulies

回答

0

在您的客戶端代碼中,爲服務指定了一個名稱空間,這是一種很好的做法,但我沒有在服務代碼中看到該名稱空間。您的服務必須定義一個名稱空間,並且這應該與您的客戶端用於指定webservice方法的名稱空間相對應。例如。

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