2014-04-16 22 views
9

Tôi gửi yêu cầu SOAP dưới dạng HTTP POST trong SOAPUI do một số ràng buộc của dự án. Yêu cầu của tôi là ở đây:Không gặp lỗi tiêu đề SOAPAction khi gửi yêu cầu SOAP dưới dạng HTTP POST

POST httplink HTTP/1.1 
Accept-Encoding: gzip,deflate 
Content-Type: text/xml;charset=UTF-8 
SOAPAction: "urn:HPD_IncidentInterface_WS/HelpDesk_Query_Service" 
Content-Length: 725 
Host: itsm-mt-dev 
Connection: Keep-Alive 
User-Agent: Apache-HttpClient/4.1.1 (java 1.5) 


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:HPD_IncidentInterface_WS"> 
    <soapenv:Header> 
     <urn:AuthenticationInfo> 
     <urn:userName>XXXXXXXXXX</urn:userName> 
     <urn:password>XXXXXXXXX</urn:password> 
     <!--Optional:--> 
     <urn:authentication>?</urn:authentication> 
     <!--Optional:--> 
     <urn:locale>?</urn:locale> 
     <!--Optional:--> 
     <urn:timeZone>?</urn:timeZone> 
     </urn:AuthenticationInfo> 
    </soapenv:Header> 
    <soapenv:Body> 
     <urn:HelpDesk_Query_Service> 
     <urn:Incident_Number>XXXXXXXXXX</urn:Incident_Number> 
     </urn:HelpDesk_Query_Service> 
    </soapenv:Body> 
</soapenv:Envelope> 

Mặc dù tôi đã thiết lập tiêu đề SOAPAction, vẫn Tôi nhận được không có lỗi tiêu đề SOAPAction.

đáp ứng như sau:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <soapenv:Fault> 
     <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode> 
     <faultstring>no SOAPAction header!</faultstring> 
     <detail> 
      <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">itsm-mt-dev</ns2:hostname> 
     </detail> 
     </soapenv:Fault> 
    </soapenv:Body> 
</soapenv:Envelope> 

bất cứ ai có thể gợi ý cho tôi những gì chúng ta có thể làm ở đây?

+0

Trong cái nhìn WSDL của bạn cho một dòng mà trông giống như ''. SoapAction là gì đối với hoạt động 'HelpDesk_Query_Service'? –

Trả lời

15

Dường như bạn đang gửi tiêu đề soapAction không chính xác. Hãy xem WSDL và tìm ra giá trị cho phần tử soapAction cho dịch vụ đang được thử nghiệm.

Trong WSDL, hãy tìm dòng tương tự <soap:operation soapAction="http://example.com/GetLastTradePrice"/>.

3
request.Headers.Add("SOAPAction", YOUR SOAP ACTION); 
+0

Tạo httpwebrequest và sau đó thêm tiêu đề vào nó 'code'Dim bs = Encoding.UTF8.GetBytes (" xà phòng ") Dim wr Như HttpWebRequest = HttpWebRequest.Create (" xx ") wr.Headers.Add (" ur xà phòng hdr "," xxx ") wr.ContentType =" text/xml; charset = utf-8 " wr.Method =" POST " wr.ContentLength = bs.Length Dim sds Như Stream = wr.GetRequestStream () sds.Write (bs, 0, bs.Length) sds.Close() Dim wr Như WebResponse = wr.GetResponse() sds = wr.GetResponseStream() Dim sr Như StreamReader = New StreamReader (SDS) Dim strResult Như String = sr.ReadToEnd() txtResult .Text = strResult sds.Close() sr.Close() wr.Close() 'code' –

0

Tôi đã cố thêm nhận xét vào câu trả lời do ynneh đề xuất nhưng mã không thể đọc được. Câu trả lời của anh hữu ích nhưng quá ngắn.

Tạo httpwebrequest và sau đó thêm tiêu đề vào nó. Sau đây là trọn vẹn dụ:

Dim bytSoap = System.Text.Encoding.UTF8.GetBytes("soap content") 

     Dim wrRequest As HttpWebRequest = HttpWebRequest.Create("xxxxx") 

     wrRequest.Headers.Add("your soap header", "xxx") 

     wrRequest.ContentType = "text/xml; charset=utf-8" 
     wrRequest.Method = "POST" 
     wrRequest.ContentLength = bytSoap.Length 

     Dim sDataStream As Stream = wrRequest.GetRequestStream() 
     sDataStream.Write(bytSoap, 0, bytSoap.Length) 
     sDataStream.Close() 

     Dim wrResponse As WebResponse = wrRequest.GetResponse() 
     sDataStream = wrResponse.GetResponseStream() 
     Dim srReader As StreamReader = New StreamReader(sDataStream) 
     Dim strResult As String = srReader.ReadToEnd() 
     txtResult.Text = strResult 
     sDataStream.Close() 
     srReader.Close() 
     wrResponse.Close() 
0

// Delphi

var 
xmlhttp : IXMLHTTPRequest; // unit MSXML2_TLB 
begin 
xmlhttp := CoXMLHTTP.Create; 
xmlhttp.open('POST', Edit7.Text, False, EmptyParam, EmptyParam); 
xmlhttp.setRequestHeader('SOAPAction','POST') 
Các vấn đề liên quan