2014-01-08 205 views
0

我一直在为此工作了两个星期,无法完全得到答案。消费Web服务

我需要从web服务数据到一个GridView控件,使用Visual Studio 2012 的wdls是在这里:https://home-c8.incontact.com/insidews/insidews.asmx 我需要 https://login.incontact.com/insidews/insidews.asmx?op=DataDownloadReport_Run方法。

我至今是:

//created service reference called icContact 

//Created Credentials 
icContactSR.inCredentials cr = new icContactSR.inCredentials(); 
cr.busNo = xxxxxx; 
cr.password = "xxxxxxx"; 
DateTime startDate = new DateTime(2013, 12, 27, 8, 00, 00); 
DateTime endDate = new DateTime(2013, 12, 27, 9, 00, 00); 

//create request 
icContactSR.DataDownloadReport_RunRequest request = 
    new `DataDownloadReport_RunRequest(cr, reportnumber, startDate, endDate);` 

//get response 
icContactSR.DataDownloadReport_RunResponse response = new  
     icContactSR.DataDownloadReport_RunResponse(); 


//fill dataset with response 
DataSet ds = (DataSet)response.DataDownloadReport_RunResult; 



GridView1.DataSource = ds.ReadXml(response.ToString()); 
GridView1.DataBind(); 

我现在的错误:(ds.readXml(response.toString()); 异常详细信息:System.NullReferenceException:对象引用未设置为实例一个对象

我觉得我很接近找到答案,但我不知道如果它根本不知道如何从响应填充数据集,或者如果我得到的响应回来。 每个当我运行它,我的数据集是空的。 任何帮助将不胜感激。

+1

是由'response'返回什么? –

+0

在你的'fill数据集'下面设置一个断点并检查'response'。 – CodeCaster

+0

检查'ds!= null' – abto

回答

0

你可以试试这个

// object to InContact Web Service reference 
var client = new icContactSR.inSideWS() 
{ 
    inCredentialsValue = new icContactSR.inCredentials() 
    { 
     password = ******, 
     busNo = ******, 
     timeZoneName = "UTC" 
    } 
}; 

DateTime startDate = new DateTime(2013, 12, 27, 8, 00, 00); 
DateTime endDate = new DateTime(2013, 12, 27, 9, 00, 00); 

DataSet dsCallDetails = client.DataDownloadReport_Run(report_number, startDate.ToUniversalTime(), endDate.ToUniversalTime()); 

GridView1.DataSource = dsCallDetails.Tables[0]; 
GridView1.DataBind();