2012-06-07 2 views
2

jQuery Ajax를 사용하여 asmx 서비스를 호출하려고합니다.jQuery Ajax를 사용하여 비누 봉투의 사용자 정의 헤더 보내기

POST /YderWS.asmx HTTP/1.1 
Host: localhost 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://scandihealth.com/iwebservices/HentKommuner" 

<?xml version="1.0" encoding="utf-8"?> 
<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:Header> 
    <AuthHeader xmlns="http://scandihealth.com/iwebservices/"> 
     <PartnerID>string</PartnerID> 
     <SubPartnerID>string</SubPartnerID> 
     <SubPartnerType>string</SubPartnerType> 
    </AuthHeader> 
    </soap:Header> 
    <soap:Body> 
    <HentKommuner xmlns="http://scandihealth.com/iwebservices/" /> 
    </soap:Body> 
</soap:Envelope> 

위의 내용은 서비스에 보내는 SOAP 1.1 요청입니다. 아래의 호출을 사용하여 사용자 정의 비누 헤더를 설정합니다. 하지만 내 요청은 실패합니다. 아무도 나를 위해 아래 코드를 디버그하고 내가 뭘 해야할지 알려주 수 있습니까?

var authHeader = "<PartnerID>SCTEST001</PartnerID> <SubPartnerID>001</SubPartnerID> <SubPartnerType>S</SubPartnerType>"; 
//Call the page method 
$.ajax({ 
    type: "GET", 
    url: servicename + "/" + functionName, 
    beforeSend: function (xhr) { 
    xhr.setRequestHeader('AuthHeader', authHeader); 
    }, 
    success: successFn, 
    error: errorFn 
}); 

편집 * 추가 정보가이 질문에 대답 할 필요가 있으면 알려 주시기 바랍니다. *

+0

오류의 원인은 무엇입니까? 그것은 쉽게 크로스 도메인 문제가 될 수 있습니다. –

답변

3

는 .NET 웹 서비스뿐만 아니라 모든 유형의 "웹 서비스"에 대한 일반 HTTP 요청을 실행합니다. 당신은 POST 데이터로 전체 SOAP 봉투를의 SOAPAction 요청 헤더를 추가하고 전달하려는 것 :

$.ajax({ 
    type: 'POST', 
    url: servicename + "/" + functionName, 
    contentType: 'text/xml; charset=utf-8', 
    headers: { 
     SOAPAction: 'http://scandihealth.com/iwebservices/HentKommuner' 
    }, 
    data: '<?xml version="1.0" encoding="utf-8"?><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:Header><AuthHeader xmlns="http://scandihealth.com/iwebservices/"><PartnerID>string</PartnerID><SubPartnerID>string</SubPartnerID><SubPartnerType>string</SubPartnerType></AuthHeader></soap:Header><soap:Body><HentKommuner xmlns="http://scandihealth.com/iwebservices/" /></soap:Body></soap:Envelope>', 
    success: successFn, 
    error: errorFn 
}); 

당신이 jQuery를 < 1.5 사용하는 경우, 당신은이 SOAPAction 요청 헤더를 설정하기 위해 beforeSend를 사용해야합니다.

jQuery.ajax()에 대한 설명서는 http://api.jquery.com/jQuery.ajax/입니다. 당신이이를 추가 놓친처럼

+1

"headers"매개 변수가 1.5까지 추가되지 않았으므로 합리적으로 최신 상태인지 확인하십시오. –

0

이 보인다 :

contentType: 'text/xml; charset=utf-8', 
dataType: 'xml' 

이 2 줄을 추가하면 그것은 나를 셀레늄으로 디버깅 잘 작동합니다.

관련 문제