我一直在研究一個項目,以連接到我們的時間報告供應商的SOAP服務並每週獲取一個報告(REST不提供獲取期望的報告)。他們只給了我們已沒有幫助的WSDL:https://secure.entertimeonline.com/ta/padnos.wsdl和 https://secure.saashr.com/ta/PADNOS.soap使用SOAP Web服務(Kronos SaasHR)並將響應保存到SQL服務器中
我已經加入了服務引用我的解決方案和生成的代理類,但每次我嘗試的時間來獲取數據,我得到的錯誤說法「沒有很好地形成響應XML。」和「數據在根級別是無效的。行1,位置1」
這是我首次涉足消費Web服務,我無法找到任何有用的材料。
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,也沒有肥皂操作中列出的網址「操作」列: