为TFS SOAP web服务构建javascript客户端
Building a javascript client for the TFS SOAP webservice
我正在尝试构建一个javascript客户端,获取有关TFS上活动项目的信息。
由于TFS有SOAP端点,我正在考虑使用wsdl2js (http://cxf.apache.org/docs/tools.html)来生成一个本地代理,然后调用我在该代理上需要的函数(如列表项目等)。
这是我的js代码:
function showresponse(response)
{
alert("rasp");
}
function showerror(error)
{
alert('error');
}
var test=new ClassificationSoap();
test.url="http://192.168.48.130:8080/Services/v1.0/CommonStructureService.asmx";
test.ListAllProjects(showresponse,showerror);
但是,两个响应函数都没有被调用。
根据CommonStructureService。下面是请求的样子:
POST /Services/v1.0/CommonStructureService.asmx HTTP/1.1
Host: 192.168.48.130
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Classification/03/ListAllProjects"
<?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:Body>
<ListAllProjects xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Classification/03" />
</soap:Body>
</soap:Envelope>
我解雇了fiddler,下面是我的原始请求:
OPTIONS http://192.168.48.130:8080/Services/v1.0/CommonStructureService.asmx HTTP/1.1
Host: 192.168.48.130:8080
Connection: keep-alive
Cache-Control: max-age=0
Access-Control-Request-Method: POST
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30
Access-Control-Request-Headers: MessageType, SOAPAction, Content-Type
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
如您所见,没有发送xml。
原始回复:
HTTP/1.1 401 Unauthorized
Content-Length: 1656
Content-Type: text/html
Server: Microsoft-IIS/6.0
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
Date: Wed, 27 Jul 2011 17:14:08 GMT
Proxy-Support: Session-Based-Authentication
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>You are not authorized to view this page</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<STYLE type="text/css">
BODY { font: 8pt/12pt verdana }
H1 { font: 13pt/15pt verdana }
H2 { font: 8pt/12pt verdana }
A:link { color: red }
A:visited { color: maroon }
</STYLE>
</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD>
<h1>You are not authorized to view this page</h1>
You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.
<hr>
<p>Please try the following:</p>
<ul>
<li>Contact the Web site administrator if you believe you should be able to view this directory or page.</li>
<li>Click the <a href="javascript:location.reload()">Refresh</a> button to try again with different credentials.</li>
</ul>
<h2>HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.<br>Internet Information Services (IIS)</h2>
<hr>
<p>Technical Information (for support personnel)</p>
<ul>
<li>Go to <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>401</b>.</li>
<li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr),
and search for topics titled <b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error Messages</b>.</li>
</ul>
</TD></TR></TABLE></BODY></HTML>
它说它需要认证
为什么没有调用showerror函数?我的客户端如何知道如何向用户请求凭据?
另外,身份验证是如何工作的?
我知道我需要发送一个包含base64编码的"user:pass"的授权头,但我在生成的Classification.js
中找不到任何参考。谢谢
您会注意到您的第一个请求是一个OPTIONS请求,而不是POST请求。您是否使用XMLHTTPRequest将请求发送到跨域服务器?如果是这样,服务器需要配置,通过CORS,返回一个Access-Control-Allow-Origin指令,以响应飞行前选项请求。
相关文章:
- 为初学者构建JavaScript中的类
- 如何使用数组和映射函数构建 JavaScript 对象
- 如何构建 Javascript Array Delta
- 构建 JavaScript 项目 Travis-CI 时出错
- 从另一个函数构建javascript数组
- 如何使用数组值动态构建javascript对象
- 构建JavaScript对象PHP循环时缺少字符
- 如何为team foundation service构建javascript测试项目
- 陷入了动态构建javascript对象的困境
- 基于元素数组中的父属性构建javascript树
- 构建JavaScript对象使用jQuery .css()(什么是重复的键?)
- 从头开始构建JavaScript网格
- 构建Javascript模块
- 如何使用Browserify和页面特定的documentReady函数构建Javascript
- 构建Javascript数组数据
- 在网站中构建javascript/jquery
- 循环复选框和构建JavaScript对象文字
- 使用模块化方法构建JavaScript应用程序
- 在.net MVC应用程序中构建javascript
- 如何构建javascript字符串,所以vbScript分裂将它分裂成一个数组