2012-12-13 49 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