从PL / SQL调用SOAP Web服务

时间:2014-08-08 03:24:35

标签: soap plsql

我有一个.net SOAP,我想从PL / SQL

调用它
DECLARE


-- SOAP REQUESTS/RESPONSE
   soap_req_msg    VARCHAR2 (2000);
   soap_resp_msg   VARCHAR2 (2000);

   -- HTTP REQUEST/RESPONSE
   http_req        UTL_HTTP.req;
   http_resp       UTL_HTTP.resp;

BEGIN
   --
   -- Create SOAP request via HTTP
   --
   soap_req_msg := 
      '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:MessageID>urn:uuid:1d66c9a8-b5e2-4c7a-9649-0bd63a590372</wsa:MessageID><wsa:Action>http://tempuri.org/IDataInterfaceService/Connect</wsa:Action><wsa:To>http://localhost:3038/</wsa:To></soapenv:Header><soapenv:Body><ns1:Connect xmlns:ns1="http://tempuri.org/"/></soapenv:Body></soapenv:Envelope>';

   http_req :=UTL_HTTP.begin_request('http://localhost:3038/', 'POST', 'HTTP/1.1');
   UTL_HTTP.set_header (http_req, 'Accept-Encoding', 'gzip,deflate');
   UTL_HTTP.set_header (http_req, 'Content-Type', 'application/soap+xml;charset=UTF-8;action="http://tempuri.org/IDataInterfaceService/Connect"');
   UTL_HTTP.set_header (http_req, 'Content-Length', length(soap_req_msg));
   UTL_HTTP.set_header (http_req, 'Host', 'localhost:3038');
   UTL_HTTP.set_header (http_req, 'Connection', 'Keep-Alive');
   UTL_HTTP.set_header (http_req, 'User-Agent', 'Apache-HttpClient/4.1.1 (java 1.5)');
   UTL_HTTP.write_text (http_req, soap_req_msg);

  dbms_output.put_line(' ');
  --
   -- Invoke Request and get Response.
   --
   http_resp := UTL_HTTP.get_response(http_req);
   UTL_HTTP.read_text (http_resp, soap_resp_msg);
   UTL_HTTP.end_response (http_resp);
   DBMS_OUTPUT.put_line ('Output: ' || soap_resp_msg);
END;
/

请求在SOAPUI中运行良好。但不是在PL / SQL

以下是回复:

Output: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>

想知道我的标题名称有什么问题......有人可以帮我吗?

附加:这是来自SOAPUI的RAW XML副本

POST http://localhost:3038/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/IDataInterfaceService/Connect"
Content-Length: 441
Host: localhost:3038
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:MessageID>urn:uuid:1d66c9a8-b5e2-4c7a-9649-0bd63a590372</wsa:MessageID><wsa:Action>http://tempuri.org/IDataInterfaceService/Connect</wsa:Action><wsa:To>http://localhost:3038/</wsa:To></soapenv:Header><soapenv:Body><ns1:Connect xmlns:ns1="http://tempuri.org/"/></soapenv:Body></soapenv:Envelope>

2 个答案:

答案 0 :(得分:1)

尝试删除此行

UTL_HTTP.set_header (http_req, 'Host', 'localhost:3038');

答案 1 :(得分:0)

尝试将Content-Type标头分成2个标头:

UTL_HTTP.set_header (http_req, 'Content-Type', 'application/soap+xml;charset=UTF-8');
UTL_HTTP.set_header (http_req, 'SOAPAction','"http://tempuri.org/IDataInterfaceService/Connect"');