我正在尝试从PL / SQL代码调用web服务,该代码将接受itemnumber作为输入参数,并将返回大约8个输出参数,一些是字符串,而几个将是base64binay编码的PDF文件。
当我从SoapUI测试相同的WSDL时,它会返回正确的响应。
但在我的PL / SQL代码中,我得到415不支持的媒体类型错误。你能不能帮我解决这个问题,我在最近5天遇到了这个错误。提前谢谢。
下面是我的虚拟代码,一旦工作正常,我需要转换为正确的函数。
declare
soap_request varchar2(30000);
soap_respond CLOB;
soap_respond_temp CLOB;
http_req utl_http.req;
http_resp utl_http.resp;
l_resp XMLType;
i integer;
instr_start integer;
instr_end integer;
l_orgname varchar2(30000);
l_description VARCHAR2(250);
l_long_description VARCHAR2(1000);
l_segment1 VARCHAR2(250);
l_item_type VARCHAR2(100);
l_isbn VARCHAR2(100);
l_match_score NUMBER;
l_pdh_id NUMBER;
l_cross_reference_id NUMBER;
l_soap_request CLOB;
l_soap_response CLOB;
l_soap_resp_raw LONG RAW;
l_buffer_size NUMBER (10) := 512;
l_substring_msg VARCHAR2 (512);
l_string_request VARCHAR2 (512);
l_raw_data RAW (512);
buffer VARCHAR2 (32767);
i NUMBER;
eob BOOLEAN := FALSE;
resultvar VARCHAR2 (30000);
begin
--Item number 104PT is I/p parameter below to the SOAP webservice
soap_request:= '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:grad="http://grades.web.spec.quality.asmorg.com/">
<soap:Header/>
<soap:Body>
<grad:getGradeInfoForRM>
<strRMItem>104PT</strRMItem>
</grad:getGradeInfoForRM>
</soap:Body>
</soap:Envelope>';
http_req:= utl_http.begin_request
( 'http://112.18.28.38:81/Itemspec/ItemGradeWSPort'
, 'POST'
, 'HTTP/1.1'
);
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header(http_req, 'SOAPAction', '');
utl_http.write_text(http_req, soap_request);
http_resp:= utl_http.get_response(http_req);
--dbms_output.put_line('got the soap response');
dbms_output.put_line('Response> status_code: "' ||http_resp.status_code || '"');
dbms_output.put_line('Response> reason_phrase: "' ||http_resp.reason_phrase || '"');
dbms_output.put_line('Response> http_version: "' ||http_resp.http_version || '"');
DBMS_LOB.createtemporary (l_soap_response, TRUE);
fnd_file.put_line(fnd_file.log,'After create temporary');
WHILE NOT (eob)
LOOP
BEGIN
dbms_output.put_line ('before read_text');
UTL_HTTP.read_text (http_resp, buffer, 32767);
fnd_file.put_line( fnd_file.log,'Printing Buffer '||buffer);
dbms_output.put_line( 'Printing Buffer '||buffer);
IF buffer IS NOT NULL AND LENGTH (buffer) > 0
THEN
fnd_file.put_line( fnd_file.log,'Appending to l_soap_response using DBMS writeappend');
dbms_output.put_line (' Appending to l_soap_response using DBMS writeappend');
DBMS_LOB.writeappend (l_soap_response, LENGTH (buffer), buffer);
END IF;
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
fnd_file.put_line( fnd_file.log,'end of body');
eob := TRUE;
END;
END LOOP;
UTL_HTTP.end_response (http_resp);
fnd_file.put_line (fnd_file.log,'before XMLTYPE Call');
dbms_output.put_line ('before XMLTYPE Call');
l_resp := XMLTYPE.createxml (l_soap_response);
DBMS_LOB.freetemporary (l_soap_response);
fnd_file.put_line(fnd_file.log,'--after XMLTYPE Call');
dbms_output.put_line ('after XMLTYPE Call');
resultvar := l_resp.getstringval();
fnd_file.put_line(fnd_file.log,'--after getstringval Call');
fnd_file.put_line (fnd_file.log,resultvar);
fnd_file.put_line ( fnd_file.log,'End DateTime:- ' || SYSTIMESTAMP);
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
dbms_output.put_line('end of body');
UTL_HTTP.end_response(http_resp);
WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN
UTL_HTTP.END_RESPONSE(http_resp);
WHEN OTHERS THEN
dbms_output.put_line('others eception '||SQLERRM);
end;
这是打印的日志消息:
响应&GT; status_code:&#34; 415&#34; 响应&GT; reason_phrase:&#34;不支持的媒体类型&#34; 在read_text之前 在XMLTYPE调用之前 其他eception ORA-31011:XML解析失败 ORA-19202:XML处理发生错误 LPX-00229:输入源为空
答案 0 :(得分:0)
此问题现已解决,问题是根据SOAP Web服务类型设置标头不正确。
sys.UTL_HTTP.SET_HEADER(http_req, 'Content-Type', 'application/soap+xml;charset=UTF-8');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header (http_req, 'Transfer-Encoding', 'chunked');
sys.utl_http.set_header(http_req, 'User-Agent', 'Apache-HttpClient/4.1.1 (java 1.5)');
utl_http.set_header(http_req, 'SOAPAction', '');
关于正确标题类型的线索,即“内容类型”和“用户代理”,我在查看Raw标签时从SoapUI获得。
谢谢, 普拉迪普