用于Quest诊断的SOAP请求出现问题(使用Visual Studio 2010、C#、ASP.NET)

用于Quest诊断的SOAP请求出现问题(使用Visual Studio 2010、C#、ASP.NET),c#,asp.net,.net,visual-studio-2010,soap,C#,Asp.net,.net,Visual Studio 2010,Soap,我不熟悉SOAP,正在尝试向Quest Diagnostics发出请求,但它似乎不起作用。尝试发出请求时,我收到一个500内部服务器错误 这是我的密码: /// <summary> /// Test SOAP Request /// </summary> /// <returns>A boolean value indicating whether the function executed successfully or not.</returns&g

我不熟悉SOAP,正在尝试向Quest Diagnostics发出请求,但它似乎不起作用。尝试发出请求时,我收到一个500内部服务器错误

这是我的密码:

/// <summary>
/// Test SOAP Request
/// </summary>
/// <returns>A boolean value indicating whether the function executed successfully or not.</returns>
private bool TestSoap()
{
    // declare necessary objects and variables
    MailMessage mailMsg;
    HttpWebRequest webRequest;
    SmtpClient smtpClient = new SmtpClient();
    ESServiceSoapClient soapClient = new ESServiceSoapClient();
    XmlDocument soapEnvelope = new XmlDocument();
    string soapResult;

    webRequest = (HttpWebRequest)WebRequest.Create("https://qcs-uat.questdiagnostics.com/services/esservice.asmx");
    webRequest.Headers.Add("SOAPAction", "https://qcs-uat.questdiagnostics.com/services/esservice.asmx?WSDL");
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";

    soapEnvelope.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?><soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:wss=""http://wssim.labone.com/""><soapenv:Header/><soapenv:Body><wss:FullRetrieveCollectionSiteDetails><wss:username>#user name#</wss:username><wss:password># password #</wss:password></wss:FullRetrieveCollectionSiteDetails></soapenv:Body></soapenv:Envelope>");

    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelope.Save(stream);
    }

    // attempt async call
    IAsyncResult asyncReslt = webRequest.BeginGetResponse(null, null);

    // suspend
    asyncReslt.AsyncWaitHandle.WaitOne();

    // get soap result
    using (WebResponse webResponse = webRequest.EndGetResponse(asyncReslt))
    {
        using (StreamReader sReader = new StreamReader(webResponse.GetResponseStream()))
        {
            soapResult = sReader.ReadToEnd();
        }
    }

    mailMsg = new MailMessage("info@evance.com", "rchristiansen@evance.com");
    mailMsg.Subject = "SOAP XML Test Request - Quest Diagnostics";
    mailMsg.Body = soapResult;

    // attempt to send message
    try
    {
        smtpClient.Send(mailMsg);
    }
    catch (Exception ex)
    {
        this.lblError.Text = "Unable to send report email to applicant: " + ex.Message;
        return false;
    }

    // return true - function executed successfully
    return true;
}
//
///测试SOAP请求
/// 
///一个布尔值,指示函数是否成功执行。
私有booltestsoap()
{
//声明必要的对象和变量
mailmessg;
HttpWebRequest-webRequest;
SmtpClient SmtpClient=新的SmtpClient();
ESServiceSoapClient soapClient=新的ESServiceSoapClient();
XmlDocument soapEnvelope=新的XmlDocument();
字符串soapResult;
webRequest=(HttpWebRequest)webRequest.Create(“https://qcs-uat.questdiagnostics.com/services/esservice.asmx");
webRequest.Headers.Add(“SOAPAction”https://qcs-uat.questdiagnostics.com/services/esservice.asmx?WSDL");
webRequest.ContentType=“text/xml;charset=\”utf-8\”;
webRequest.Accept=“text/xml”;
webRequest.Method=“POST”;
LoadXml(@“#用户名###密码#”);
使用(Stream-Stream=webRequest.GetRequestStream())
{
soapEnvelope.Save(流);
}
//尝试异步调用
IAsyncResult asyncReslt=webRequest.BeginGetResponse(null,null);
//暂停
asyncReslt.AsyncWaitHandle.WaitOne();
//获得soap结果
使用(WebResponse WebResponse=webRequest.EndGetResponse(asyncReslt))
{
使用(StreamReader sReader=newstreamreader(webResponse.GetResponseStream())
{
soapResult=sReader.ReadToEnd();
}
}
mailMsg=新邮件消息(“info@evance.com", "rchristiansen@evance.com");
mailMsg.Subject=“SOAP XML测试请求-任务诊断”;
mailMsg.Body=soapResult;
//尝试发送消息
尝试
{
smtpClient.Send(mailMsg);
}
捕获(例外情况除外)
{
this.lblError.Text=“无法向申请人发送报告电子邮件:”+例如消息;
返回false;
}
//返回true-函数已成功执行
返回true;
}
我删除了用户名和密码,这样你就不用自己尝试访问了。再说一次,我对肥皂还不熟悉,我不知道到底出了什么问题。请注意,我确实有一些未使用的代码,例如ESServiceSoapClient。对象中的函数有一个指定的方法,但该方法也不起作用(为此获得了EndpointNotFoundException)。

尝试更改此代码

// get soap result
using (WebResponse webResponse = webRequest.EndGetResponse(asyncReslt))
{
    using (StreamReader sReader = new StreamReader(webResponse.GetResponseStream()))
    {
        soapResult = sReader.ReadToEnd();
    }
}
为此:

// get soap result
using (WebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asyncReslt))
{
    using (Stream dataStream = webResponse.GetResponseStream())
    {
        StreamReader sReader = new StreamReader(webResponse.GetResponseStream())
        soapResult = sReader.ReadToEnd();
    }
}
更改:直接将webRequest强制转换为webResponse,为getResponseStream方法添加了一行

loadXml开头的@符号也应该存在吗

参考资料:


我想大部分代码都来自他们的api。你可以发布一个到api页面的链接,或者只是澄清一下这是否是原始api代码。这是原始的SOAP请求框架:这不是我的意思。我在问是否有类似于此特定操作的页面,您从中获得了大量此代码?我收到了一个包含此信息的Word文档。我不能把它贴在这里。若你们能给我你们的电子邮件地址,也许我可以通过那个种方式发送。若它是word文档,那个么它可能是根据保密协议的,至少从PCI的经验来看,你们能在你们更改的每一行上面添加注释吗。应该从中得到一个好主意。