我有以下合同的Web服务:
I have a web service with the following contract:
POST /Service/service.asmx HTTP/1.1
Host: xxx.xxx.xxx
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "xxx.xxx.xxx/Service/Method"
<?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>
<Request xmlns="xxx.xxx.xxx/Service/">
<transactiontype>string</transactiontype>
<username>string</username>
<password>string</password>
</Request>
</soap:Header>
<soap:Body>
<Method xmlns="xxx.xxx.xxx/Service/">
<xml>xml</xml>
</Method>
</soap:Body>
</soap:Envelope>
和我想打电话给使用jQuery的服务。这是我的code:
And I am trying to call the service using jquery. This is my code:
$.ajax({
url: serverUrl + 'Method',
type: "POST",
dataType: "xml",
data: { xml: "xml" },
beforeSend: function (req) {
req.setRequestHeader('Header', '<Request xmlns="xxx.xxx.xxx/Service/">'
+'<transactiontype>4</transactiontype>'
+'<agencyName>name</agencyName>'
+'<username>user</username>'
+'<password>pass</password>'
+'</Request>');
},
success: function (data) {
alert(data.text);
},
error: function (request, status, errorThrown) {
alert(status);
}
});
然而,首标内容不传递到Web服务?我怎么会去传递头凭据我的Web服务调用?
However, the header content is not passed to the web service? How would I go about passing the header credentials to my web service call?
推荐答案
香皂:标题
是内部的XML / SOAP数据有效载荷的XML元素。这是不是一个 HTTP头不同。在合同中,的SOAPAction
(连同内容长度
等)是一个HTTP标头。
soap:Header
is an XML element inside the XML/SOAP data "payload". This is different than an HTTP headers. In the contract, SOAPAction
(along with Content-Length
, etc) is an HTTP header.
XmlHtt prequest.setRequestHeader
用于指定HTTP头。它无关,与任何XML中的(直接)。
XmlHttpRequest.setRequestHeader
is used for specifying HTTP headers. It has nothing to do with anything inside the XML (directly).
在最简单的例子SOAP使用Javascript第一个答案应该给予怎样的一个例子做一个SOAP请求。注:
The first answer at Simplest SOAP example using Javascript should give an example of how to make a SOAP request. Note:
xmlhttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote");
xmlhttp.setRequestHeader("Content-Type", "text/xml");
...
var xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope...' + etc;
xmlhttp.send(xml)
这是一个包含香皂的XML:信封
的子元素香皂:标题
和香皂:身体
快乐编码。
相关推荐
最新文章