使用 SOAP Web 服务 (Kronos SaasHR) 并将响应保存到 SQL 服务器
Consuming a SOAP web service (Kronos SaasHR) and saving response into SQL server
我一直致力于连接到我们的时间报告供应商的 SOAP 服务并每周获取报告的项目(REST 不提供获取所需报告的函数调用)。他们只给了我们没有帮助的 WSDL:https://secure.entertimeonline.com/ta/padnos.wsdl 和
https://secure.saashr.com/ta/PADNOS.soap
我已将服务引用添加到我的解决方案并生成了代理 class,但每次我尝试获取数据时,都会收到错误消息“响应格式不正确XML.”和“根级别的数据无效。第 1 行,位置 1。”
这是我第一次尝试使用 Web 服务,我找不到任何有用的东西 material。
private void btnGo_Click(object sender, EventArgs e)
{
// service reference
// runReportByName
TSPHoursWorked.ServiceReference1.runReport_ByNameType rptName = new ServiceReference1.runReport_ByNameType();
rptName.version = 1;
rptName.reportCategory = "Calculated Time";
rptName.reportName = "Calculated Time By Entry";
rptName.reportSavedName = "DailyHoursWorked";
rptName.outputType = TSPHoursWorked.ServiceReference1.runReport_ByNameTypeOutputType.XML;
TSPHoursWorked.ServiceReference1.SaaSHRClient soap = new ServiceReference1.SaaSHRClient();
soap.ClientCredentials.UserName.UserName = "username";
soap.ClientCredentials.UserName.Password = "password";
var requestInterceptor = new InspectorBehavior();
soap.Endpoint.Behaviors.Add(requestInterceptor);
soap.runReport_ByName(rptName);
string requestXML = requestInterceptor.LastRequestXML;
outputText.Text = requestXML;
string responseXML = requestInterceptor.LastResponseXML;
outputText.Text += responseXML;
}
public class InspectorBehavior : IEndpointBehavior
{
public string LastRequestXML
{
get
{
return myMessageInspector.LastRequestXML;
}
}
public string LastResponseXML
{
get
{
return myMessageInspector.LastResponseXML;
}
}
private MyMessageInspector myMessageInspector = new MyMessageInspector();
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(myMessageInspector);
}
}
public class MyMessageInspector : IClientMessageInspector
{
public string LastRequestXML { get; private set; }
public string LastResponseXML { get; private set; }
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
LastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
LastRequestXML = request.ToString();
return request;
}
}
我只想连接到他们的 Web 服务,获取报告并批量插入 SQL 服务器。谁能让我走上正确的道路?
编辑:
我已经安装了 SoapUI,但在 soap 操作 "Actions" 列下没有列出任何 URL:
问题是我们的 Kronos 中间商供应商没有任何技术知识。几周后终于与 Kronos 取得联系,我被告知:
- 必须创建一个新用户没有单点登录
- 将主管理员帐户的groups/reports/etc复制到新帐户
- 为新帐户添加最高安全权限
然后您就可以调用RESTful服务了。我希望这对某人有所帮助,因为我们的供应商浪费了我们 2 周的时间
我一直致力于连接到我们的时间报告供应商的 SOAP 服务并每周获取报告的项目(REST 不提供获取所需报告的函数调用)。他们只给了我们没有帮助的 WSDL:https://secure.entertimeonline.com/ta/padnos.wsdl 和 https://secure.saashr.com/ta/PADNOS.soap
我已将服务引用添加到我的解决方案并生成了代理 class,但每次我尝试获取数据时,都会收到错误消息“响应格式不正确XML.”和“根级别的数据无效。第 1 行,位置 1。”
这是我第一次尝试使用 Web 服务,我找不到任何有用的东西 material。
private void btnGo_Click(object sender, EventArgs e)
{
// service reference
// runReportByName
TSPHoursWorked.ServiceReference1.runReport_ByNameType rptName = new ServiceReference1.runReport_ByNameType();
rptName.version = 1;
rptName.reportCategory = "Calculated Time";
rptName.reportName = "Calculated Time By Entry";
rptName.reportSavedName = "DailyHoursWorked";
rptName.outputType = TSPHoursWorked.ServiceReference1.runReport_ByNameTypeOutputType.XML;
TSPHoursWorked.ServiceReference1.SaaSHRClient soap = new ServiceReference1.SaaSHRClient();
soap.ClientCredentials.UserName.UserName = "username";
soap.ClientCredentials.UserName.Password = "password";
var requestInterceptor = new InspectorBehavior();
soap.Endpoint.Behaviors.Add(requestInterceptor);
soap.runReport_ByName(rptName);
string requestXML = requestInterceptor.LastRequestXML;
outputText.Text = requestXML;
string responseXML = requestInterceptor.LastResponseXML;
outputText.Text += responseXML;
}
public class InspectorBehavior : IEndpointBehavior
{
public string LastRequestXML
{
get
{
return myMessageInspector.LastRequestXML;
}
}
public string LastResponseXML
{
get
{
return myMessageInspector.LastResponseXML;
}
}
private MyMessageInspector myMessageInspector = new MyMessageInspector();
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(myMessageInspector);
}
}
public class MyMessageInspector : IClientMessageInspector
{
public string LastRequestXML { get; private set; }
public string LastResponseXML { get; private set; }
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
LastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
LastRequestXML = request.ToString();
return request;
}
}
我只想连接到他们的 Web 服务,获取报告并批量插入 SQL 服务器。谁能让我走上正确的道路?
编辑:
我已经安装了 SoapUI,但在 soap 操作 "Actions" 列下没有列出任何 URL:
问题是我们的 Kronos 中间商供应商没有任何技术知识。几周后终于与 Kronos 取得联系,我被告知:
- 必须创建一个新用户没有单点登录
- 将主管理员帐户的groups/reports/etc复制到新帐户
- 为新帐户添加最高安全权限
然后您就可以调用RESTful服务了。我希望这对某人有所帮助,因为我们的供应商浪费了我们 2 周的时间