2012-11-19 38 views
5

TLDR; nhìn vào paragrap cuối cùng.Tiêu thụ dịch vụ WCF từ Oracle

Nhà phát triển từ công ty phần mềm đối tác của chúng tôi cần gọi dịch vụ WCF (http cơ bản ràng buộc) của chúng tôi. Dịch vụ WCF đang được sử dụng trên các nền tảng khác nhau (.net, java, php) mà không có lỗi.

Mã của anh ấy cung cấp cho anh ta Mã trạng thái: 500 - Lỗi máy chủ nội bộ. Tôi giả định về việc gửi sai định dạng xà phòng hoặc nội dung.

Vì vậy, tôi đã học được bạn nên sử dụng utl_dbws thay vì utl_http như nhà phát triển đã làm.

Ok, điều này dường như là một nhiệm vụ dễ dàng đối với tôi trước tiên. Tìm một mẫu mã làm việc từ internet và gửi một e-mail như "Xin chào bạn đồng nghiệp của nhà phát triển, bạn nên sử dụng gói utl_dbws không phải utl_http và mã mẫu tại liên kết này".

Tôi không phải là người duy nhất trên thế giới cần thực hiện việc này, đúng không?

Lạ lùng nhưng tôi không thể tìm thấy bất kỳ mẫu mã được phê duyệt mẫu nào đã thực hiện gọi dịch vụ WCF từ Oracle.

Đây là một số liên kết tôi tìm thấy về nó;

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

Noone viết bất kỳ mã ví dụ làm việc hoặc không ai nói rằng điều này là không thể.

Tôi sẽ đánh giá cao nếu có ai đó có ví dụ mã hoạt động gọi dịch vụ WCF từ Oracle.

+1

Tôi đã từng chơi với UTL_DBWS trong quá khứ để gọi các dịch vụ web đơn giản, nhận thấy nó không hoạt động tốt và không tìm được hỗ trợ nhiều. Tôi đã sử dụng UTL_HTTP thay vào đó. –

+0

@Jeffrey Kemp, Bạn đã quản lý các cuộc gọi WCF với UTL_HTTP chưa? – berdem

+0

Tôi chưa từng sử dụng dịch vụ WCF trước đây. –

Trả lời

0

Khi bạn gặp lỗi Http 500, thường là lỗi nội bộ. Ví dụ: nhà phát triển đang gọi dịch vụ của bạn mà không đặt tất cả các giá trị đầu vào, sau đó mã của bạn có thể tạo ra một lỗi bằng 0, khi không bị bắt được trả lại cho máy khách dưới dạng lỗi http 500.

Bạn có thể định cấu hình phiên bản xà phòng của dịch vụ WCF giống như dịch vụ asmx.

0

Nếu bạn đang nhận được phản hồi 500 (lỗi nội bộ) từ dịch vụ WCF, hãy thử đặt trong web.config của dịch vụ WCF includeexceptiondetailinfaults = true. (http://msdn.microsoft.com/cs-cz/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults(v=vs.110).aspx)

Sau đó, bạn sẽ nhận được ngoại lệ cụ thể (hành động xà phòng sai, sai định dạng ...)

Gọi dịch vụ WCF từ PL/SQL.

utl_http nhưng nó hoạt động.

/* 
    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; 
Các vấn đề liên quan