Vai*_*ain 3 .net ajax jquery asmx soapheader
我正在尝试使用 jQuery Ajax 调用 asmx 服务。
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>
Run Code Online (Sandbox Code Playgroud)
以上是我需要发送到服务的 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
});
Run Code Online (Sandbox Code Playgroud)
编辑*如果需要其他信息来回答这个问题,请告诉我。*
jQuery.ajax()为任何类型的“Web 服务”发出通用 HTTP 请求,而不仅仅是 .NET Web 服务。您需要添加 SOAPAction 请求标头并将整个 SOAP 信封作为 POST 数据传递:
$.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
});
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 jQuery < 1.5,则需要使用beforeSendSOAPAction 请求标头来设置。
jQuery.ajax()您可以在http://api.jquery.com/jQuery.ajax/找到文档。
| 归档时间: |
|
| 查看次数: |
10207 次 |
| 最近记录: |