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

时间:2011-07-27 17:36:41

标签: javascript soap tfs authorization fiddler

我正在尝试构建一个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.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>

我解雇了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>

所以基本上它说它需要身份验证。

为什么没有调用淋浴功能?我的客户如何知道如何向用户询问凭据?

此外,身份验证如何运作?

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

由于

1 个答案:

答案 0 :(得分:1)

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