2012-11-19 127 views
5

TLDR;看看最後一個章節。從Oracle消費WCF服務

從我們的合作伙伴的軟件公司開發人員需要調用WCF我們(基本http綁定)服務,他要求我們把它交給ASMX自己,因爲他有麻煩,從Oracle調用它。 WCF服務正在不同的平臺上(.net,java,php)使用,沒有任何錯誤。

他的代碼給他狀態碼:500 - 內部服務器錯誤。我假設它發送錯誤的肥皂格式或內容。

讓我學到,你應該使用UTL_DBWS,而不是UTL_HTTP爲開發商做。

好的,這對我來說似乎是一件容易的事。從互聯網上找到一個有效的代碼示例,併發送一封電子郵件,如「嗨同伴開發者的朋友,你應該使用utl_dbws包不utl_http和示例代碼在這個鏈接」。

我不是世界上唯一需要這樣做的人,對嗎?

奇怪,但我找不到任何示例批准的代碼工作,完成從Oracle調用WCF服務。

這是我發現的一些鏈接;

https://forums.oracle.com/forums/thread.jspa?threadID=2354357 https://forums.oracle.com/forums/thread.jspa?threadID=1071996 http://steveracanovic.blogspot.com/2008/10/using-utldbws-package-to-call-web.html https://forums.oracle.com/forums/thread.jspa?messageID=4205205&tstart=0#4205205
http://www.oracle-base.com/articles/10g/utl_dbws-10g.php

沒有人寫任何工作代碼示例或沒有人告訴,這是不可能的。

如果有人有從Oracle調用WCF服務的工作代碼示例,我將不勝感激。

+1

我以前曾經玩過UTL_DBWS來調用簡單的Web服務,發現它並不是特別好用,並且沒有找到太多的支持。我最終使用了UTL_HTTP。 –

+0

@Jeffrey Kemp,您是否設法使用UTL_HTTP處理WCF調用? – berdem

+0

我從來沒有使用過WCF服務。 –

回答

0

當您收到Http 500錯誤時,通常是內部錯誤。例如,開發人員在不設置所有輸入值的情況下調用您的服務,那麼您的代碼可能會生成一個被零除錯誤的錯誤,該錯誤在未捕獲時會以http 500錯誤的形式返回給客戶端。

您可以將WCF服務的soap版本配置爲與asmx服務相同。

0

如果您從WCF服務獲得響應500(內部錯誤),請嘗試在WCF服務的web.config中設置includeexceptiondetailinfaults = true。 (http://msdn.microsoft.com/cs-cz/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults(v=vs.110).aspx

然後你會得到詳細的異常(錯誤的SOAP動作,誤格式化...)從PL/SQL

調用WCF服務。

utl_http但它的工作原理。

/* 
    declare 
    p_request VARCHAR(32767); 
    p_plainResult VARCHAR2(32767); 
    begin 
    p_request := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:Sum> 
     <tem:a>1</tem:a> 
     <tem:b>2</tem:b> 
     </tem:Sum> 
    </soapenv:Body> 
</soapenv:Envelope>'; 

select callSOAPService(p_request,'http://tempuri.org/IMathService/Sum','http://localhost:51106/MathService.svc') into p_plainResult from dual;  
    end; 

    */ 
create or replace function callSOAPService 
( 
p_plainRequest IN varchar2(20000), 
p_actionName IN varchar2(1024), --SOAP Action (in WCF, attribute [OperationContract(Action="ActionName") 
p_url IN varchar2(1024), 
    p_userName varchar2(1024) := null, 
    p_password varchar2(1024) := null, 
    p_isAsynchronous boolean:= FALSE, 
    p_proxy varchar2(1024):=null, 
    p_transferTimeout number :=null, 
) 
RETURN VARCHAR2(32767) 
IS 
    p_charset varchar2(1024) :='AL32UTF8'; --by default utf-8 
    p_request utl_http.req; 
    p_response utl_http.resp; 
    p_plainResponse varchar2(32767); 
BEGIN 

    p_url := utl_url.escape(url => p_url); --escape url 

    if p_TransferTimeout > 0 THEN --set oracle timeout (by defualt is 60 sec) 
    utl_http.set_transfer_timeout(timeout => p_transferTimeout); 
    END IF; 

    if p_proxy IS NOT NULL THEN --if proxy is provided, then set it 
    utl_http.set_proxy(proxy => p_proxy); 
    end if; 
    utl_http.set_response_error_check(enable => TRUE); --http status errorCheck (404 not found, 500 internal error...) 
    utl_http.set_detailed_excp_support(enable => TRUE); --detailed error stack 

    p_request := UTL_HTTP.begin_request(url => p_url,method => 'POST' /*u SOAP bude vzdy POST meotda*/ ,http_version => 'HTTP/1.1'); 

    --pripravim si obalku 
    UTL_HTTP.set_header (r => p_request,name => 'Content-Type', value => 'text/xml'); 
    UTL_HTTP.set_header (r => p_request,name => 'Content-Length',value => LENGTH (p_plainRequest)); 
    UTL_HTTP.set_header (r => p_request, name => 'SOAPAction',value => p_actionName); --if status is 500 check SOAP action 
    UTL_HTTP.write_text(r => p_request,data => p_plainRequest); 

    p_response := UTL_HTTP.get_response (p_request); 

    if p_isAsynchronous THEN --one-way service 
     UTL_HTTP.end_response (p_response); --proto ukoncim request a vratim prazdno 
     RETURN ''; 
    end if; 

    utl_http.read_text (p_response, p_plainResponse); --read response 
    utl_http.end_response (p_response); --close resposne 

    dbms_output.put_line ('Response from: ' || p_url || ' is ' || p_plainResponse); --vypisu odpoved pro kontrolu 
    return p_plainResponse; 
EXCEPTION 
    when others then  
     dbms_output.put_line('Chyba ' || UTL_HTTP.get_detailed_sqlerrm()); --get error stack 
     utl_http.end_response (p_response); 
END;