2012-12-13 33 views
0

我是webservice中的新成員。400將xml傳遞給webservice時的錯誤請求

我通過XML來叫plog.asmx

這裏ASPX Web服務是我的代碼

String xmldata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 
      "<SOAP:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + 
       "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + 
       "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" >" + 
       "<![CD[<soap:Body>" + 
       "<SubmitJob xmlns=\"http://www.xdel.biz/XWS/\"> " + 
       "<APIKey>"+ API_KEY +"</APIKey>" + 
       "<Job>" + 
       "<Customer_Name>"+ Customer_Name +"</Customer_Name>" + 
       "<Address1>"+ Address1 +"</Address1>" + 
       "<Address2>"+ Address2 +"</Address2>" + 
       "<Postal_Code>"+ Postal_Code +"</Postal_Code>" + 
       "<Phone_Number>"+ Phone_Number +"</Phone_Number>" + 
       "<Mobile_Number>"+ Mobile_Number +"</Mobile_Number>" + 
       "<Order_Reference>"+ Order_Reference +"</Order_Reference>" + 
       "<Delivery_Instructions>"+ Delivery_Instructions +"</Delivery_Instructions>" + 
       "</Job>]]>" + 
      "</SubmitJob>" + 
       "</soap:Body>]]>" + 
       "</SOAP:Envelope>"; 

      System.out.println(xmldata); 


       try{ 
        //Create socket 
        String hostname = "www.xdel.biz"; 
        int port = 80; 
        InetAddress addr = InetAddress.getByName(hostname);      
        Socket sock = new Socket(addr, port); 
        System.out.println(sock.toString());      

        //Send header 
        String path = "/xws/plog.asmx"; 
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8")); 
        // You can use "UTF8" for compatibility with the Microsoft virtual machine. 
        wr.write("POST " + path + " HTTP/1.1\r\n"); 
        wr.write("Host: www.xdel.biz\r\n"); 
        wr.write("Content-Type: text/xml; charset=utf-8\r\n"); 
        wr.write("Content-Length: " + xmldata.length() + "\r\n");     
        wr.write("SOAPAction: \"http://www.xdel.biz/XWS/SubmitJob\" \r\n"); 
        wr.write("\r\n"); 

        //Send data 
        wr.write(xmldata); 
        wr.flush(); 

        System.out.println("1"); 

        // Response 
        BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream())); 
        String line; 
        while((line = rd.readLine()) != null){ 
         System.out.println(line); 
        } 

       } catch (Exception e) { 
        e.printStackTrace(); 
       } 

當我運行的代碼,我得到了錯誤這樣

HTTP/1.1 400錯誤請求 Cache-Control:private Content-Type:text/xml; x-AspNet-Version:4.0.30319 X-Powered-by:ASP.NET Date:Thu,13 Dec 2012 09:37:12 GMT Content-長度:0

我一派錯誤,並試圖修復,但無解出來..

回答

0

一個好的IDEIA將使用實現SOAP Web服務,並已經測試過的API。

我用,當你不匹配的協議(SOAP或HTTP)

+0

我不想使用JAX-WS。還有其他解決方案嗎? @fredcrs ..i – Raymond

+0

如果沒有解決方案,我如何將我的web服務導出到另一個項目? – Raymond

+0

theres這裏很好的答案http://stackoverflow.com/questions/3463216/java-simple-soap-client – fredcrs

0

這可能是<![CD[<soap:Body></soap:Body>]]>嘗試使用without ![CD[ ]] block

+0

我已經嘗試.. @ Giordano Maestro ..仍然有那個錯誤... – Raymond

0

我已經有「錯誤的請求這 JAX-WS

400錯誤的請求,有時會發生「消費Web服務。問題是,經過將近一天的時間尋找答案,我們發現這是所消耗的XML的大小,以及所消耗的SOAP消息的大小。問題是,提供Webservice消耗的應用程序必須設置爲接收大型XML數據,我們必須配置我們的應用程序服務器以擴展以增大用於從客戶端接收SOAP消息的緩衝區大小。

這是我們的期限。我希望能有所幫助。

0

我和HttpURLConnection有同樣的問題。添加以下兩個屬性決定,我的400錯誤請求問題:

  1. httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
  2. httpConn.setRequestProperty("soapAction", soapAction);

注:此錯誤通常,當您嘗試讀取響應出現。

+0

我需要幫助,有這個問題。你能告訴我你是如何發送SOAP信封的 – joga