为TFS SOAP Web服务构建javascript客户端

为TFS SOAP Web服务构建javascript客户端,javascript,soap,tfs,authorization,fiddler,Javascript,Soap,Tfs,Authorization,Fiddler,我正在尝试构建一个javascript客户端,该客户端获取TFS上活动项目的信息 因为TFS有SOAP端点,所以我考虑使用wsdl2js()生成一个本地代理,然后在该代理上调用我需要的函数(如列表项目等) 以下是我的js代码: function showresponse(response) { alert("rasp"); } function showerror(error) { alert('error');

我正在尝试构建一个javascript客户端,该客户端获取TFS上活动项目的信息

因为TFS有SOAP端点,所以我考虑使用wsdl2js()生成一个本地代理,然后在该代理上调用我需要的函数(如列表项目等)

以下是我的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.asmx,以下是请求的外观:

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>
如您所见,没有发送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>
HTTP/1.1 401未经授权
内容长度:1656
内容类型:text/html
服务器:Microsoft IIS/6.0
WWW:NTLM
X-Powered-By:ASP.NET
日期:2011年7月27日星期三格林尼治标准时间17:14:08
代理支持:基于会话的身份验证
您无权查看此页面
正文{font:8pt/12pt verdana}
H1{font:13pt/15pt verdana}
H2{font:8pt/12pt verdana}
A:链接{颜色:红色}
A:访问{color:maroon}
您无权查看此页面
您没有使用提供的凭据查看此目录或页面的权限,因为您的Web浏览器正在发送Web服务器未配置为接受的WWW Authenticate标头字段。

请尝试以下操作:

  • 如果您认为应该能够查看此目录或页面,请与网站管理员联系
  • 单击按钮以使用不同的凭据重试
HTTP错误401.2-未经授权:由于服务器配置,访问被拒绝。
Internet信息服务(IIS)
技术信息(针对支持人员)

  • 转到并对词语HTTP和401执行标题搜索
  • 打开IIS帮助,该帮助可在IIS管理器(inetmgr)中访问, 并搜索标题为“关于安全性、身份验证和关于自定义错误消息”的主题
所以基本上它说它需要认证

为什么不调用淋浴ROR函数?我的客户如何知道如何向用户请求凭据

还有,身份验证是如何工作的

我知道我需要发送一个授权头,其中包含用base64编码的“user:pass”,但在生成的Classification.js中找不到任何对此的引用


谢谢你会注意到你的第一个请求是选项请求,而不是帖子。您是否使用XMLHTTPRequest将请求发送到跨源服务器?如果是这样,服务器需要通过CORS进行配置,以返回一个Access Control Allow Origin指令来响应飞行前选项请求。

您是否构建了javascript客户端?那是你可以分享的吗?不,我没有。我使用了另一种方法,创建了WCF REST Web服务,并使用tfs api在tfs服务器上对用户进行身份验证。之后,服务返回了JSON,其中包含请求的信息(项目、用户故事等)。
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>