我写了一些PLSQL代码来使用我在本地PC上创建的Web服务,但我总是得到一个不支持的媒体类型异常,例外代码是415.请参阅下面的代码:
PLSQL:
declare
l_param_list varchar2(512);
l_http_request UTL_HTTP.req;
l_http_response UTL_HTTP.resp;
l_response_text varchar2(32000);
l_soap_request varchar2(32000);
begin
-- service's input parameters
l_soap_request := '<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/">
<soap:Body>
<add xmlns="http://tempuri.org/">
<firstNum>3</firstNum>
<secondNum>4</secondNum>
</add>
</soap:Body>
</soap:Envelope>';
--http://localhost:64955/Service1.asmx?op=add
--16.158.161.7
dbms_output.put_line('length of l_soap_request :' || length(l_soap_request));
dbms_output.put_line('l_soap_request : ' || l_soap_request);
-- prepareint Request...
l_http_request := UTL_HTTP.begin_request ('http://localhost:64955/Service1.asmx'
,'POST'
,UTL_HTTP.HTTP_VERSION_1_1);
--...set header's attributes
UTL_HTTP.set_header(l_http_request,'Content-Type', 'text/xml; charset=utf-8');
UTL_HTTP.set_header(l_http_request,'Content-Type', length(l_soap_request));
UTL_HTTP.set_header(l_http_request,'SOAPAction','http://tempuri.org/add');
--...set input parameters
UTL_HTTP.write_text(l_http_request, l_soap_request);
-- get response and obtain received value
l_http_response := UTL_HTTP.get_response(l_http_request);
dbms_output.put_line('Response Received');
dbms_output.put_line('________');
dbms_output.put_line('Status Code : '||l_http_response.status_code);
--UTL_HTTP.read_text(l_http_response, l_response_text);
dbms_output.put_line('Reason Phase : '||l_http_response.reason_phrase);
--dbms_output.put_line(l_response_text);
--dbms_output.put_line('test1');
utl_http.read_text(l_http_response,l_response_text);
dbms_output.put_line('Response : ');
dbms_output.put_line(l_response_text);
--finalizing
UTL_HTTP.end_response(l_http_response);
exception
when UTL_HTTP.end_of_body then
UTL_HTTP.end_response(l_http_response);
dbms_output.put_line('test2');
end;
Web服务是由.NET在C#中创建的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Calculator
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string add(string firstNum, string secondNum)
{
int p1 = Convert.ToInt32(firstNum);
int p2 = Convert.ToInt32(secondNum);
return (p1 + p2).ToString();
}
}
}
有人可以帮我解决我的代码或媒体类型的错误,正确的媒体类型是什么或者如何知道正确的媒体类型?
答案 0 :(得分:0)
您使用长度
覆盖内容类型UTL_HTTP.set_header(l_http_request,'Content-Type', length(l_soap_request));
相反,你应该这样做:
UTL_HTTP.set_header(l_http_request,'Content-Length', length(l_soap_request));