2010-06-02 47 views
0

我正在开发我的第一个Dashboard Widget并尝试调用Web服务。但我不断获取XMLHTTPRequest的状态0Apple Dashcode和Webservices

以下是代码

var soapHeader = '<?xml version=\"1.0\" encoding=\"utf-8\"?>\n' 
          +'<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/\">\n' 

          +'<soap:Body>\n' 
          +'<UsersOnline xmlns=\"http://wsSync\" />\n' 
          +'</soap:Body>\n' 
          +'</soap:Envelope>'; 


var destinationURI = 'http://ws.storan.com/webservicesformraiphone/wssync.asmx'; 

var actionURI = 'http://wsSync/UsersOnline'; 
function callWebService() { 
    try{ 
     SOAPObject = new XMLHttpRequest(); 
     SOAPObject.onreadystatechange = function() {fetchEnd(SOAPObject);} 
     SOAPObject.open('POST', destinationURI, true); 


     SOAPObject.setRequestHeader('SOAPAction', actionURI); 
     SOAPObject.setRequestHeader('Content-Length', soapHeader.length); 
     SOAPObject.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); 
     var requestBody = soapHeader; 
     SOAPObject.send(requestBody); 


    } catch (E) 
    { 
    alert('callWebService exception: ' + E); 
    } 
} 

function fetchEnd(obj) 
{ 

    if(obj.readyState == 4){ 

     if(obj.status==200) 
     { 
      alert("Yahooooooo"); 
     } 
    } 
} 

任何想法?

回答

1

有你加入

<key>AllowNetworkAccess</key> 
<true/> 

到的plist?如果不是外面的世界将不可用。

如果尝试跨域,您可能还会遇到问题。

+0

感谢一家工厂,这是个问题 - 搞定了! – 2010-06-08 10:39:04