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

Building a javascript client for the TFS SOAP webservice

本文关键字:构建 javascript 客户端 服务 web TFS SOAP      更新时间:2023-09-26

我正在尝试构建一个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指令,以响应飞行前选项请求。