调用C#ASMX Web服务
问题描述:
我有一个ASMX Web服务,我需要使用它作为一项工作的一部分。我通过ASPX页面调用此服务以在第三方系统上创建新实体。我无法访问该服务的底层代码,只是为了让我能够与另一个系统通信。调用C#ASMX Web服务
很难找到了,如果我呼吁正确的服务,我不知道是否有人能提供一些建议林。
我已经安装了ASMX页面,并且给了我一个类的ConfirmConnector“我称之为BeginProcessOperations方法。我想等待返回,然后解析结果。结果应该是XML格式,然后我会逐步获取我所掌握的数据。
麻烦的是,有时这个过程只是死在我身上时,即当我把我的“EndProcessOperations”的方法则什么也不会发生。我没有得到一个错误,没有什么 - 我的代码只是死了,这个方法返回
我调用的代码是:
private void sendConfirmRequest(XmlManipulator requestXML)
{
file.WriteLine("Sending CONFIRM Request!");
AsyncCallback callBack = new AsyncCallback(processConfirmXML); // assign the callback method for this call
IAsyncResult r = conn.BeginProcessOperations(requestXML, callBack, AsyncState);
System.Threading.WaitHandle[] waitHandle = { r.AsyncWaitHandle }; // set up a wait handle so that the process doesnt automatically return to the ASPX page
System.Threading.WaitHandle.WaitAll(waitHandle, -1);
}
我的处理程序代码是:
/*
* Process the response XML from the CONFIRM Connector
*/
private static void processConfirmXML(IAsyncResult result)
{
try
{
file.WriteLine("Received Response from CONFIRM!");
if(result == null)
{
file.WriteLine("RESPONSE is null!!");
}
if(conn == null)
{
file.WriteLine("conn is null!!");
}
file.WriteLine("Is Completed : " + result.IsCompleted);
XmlNode root = conn.EndProcessOperations(result);
file.WriteLine("got return XML");
//writeXMLToFile("C:/response.xml",root.InnerXml);
file.WriteLine(root.InnerXml);
谁能告知,如果我我以正确的方式处理这段代码,并且没有人知道为什么我的代码在处理器中的这条线之后随机炸弹:
XmlNode root = conn.EndProcessOperations(result);
感谢您的帮助, 保罗
答
感谢您的期待,但我解决了我的问题。这个问题似乎与我的回调操作有关。
我改变了代码来调用我开始在相同的代码块&末的方法和我还没有过一个问题,从那时起。
private void sendConfirmRequest(XmlManipulator requestXML)
{
//ConfirmConnector conn = new ConfirmConnector();
file.WriteLine("Sending CONFIRM Request!");
//AsyncCallback callBack = new AsyncCallback(processConfirmXML); // assign the callback method for this call
//IAsyncResult r = conn.BeginProcessOperations(requestXML, callBack, AsyncState);
//System.Threading.WaitHandle[] waitHandle = { r.AsyncWaitHandle }; // set up a wait handle so that the process doesnt automatically return to the ASPX page
//System.Threading.WaitHandle.WaitAll(waitHandle, -1);
file.WriteLine("Calling BeginProcessOperations");
IAsyncResult result = conn.BeginProcessOperations(requestXML, null, null);
// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();
file.WriteLine("Calling EndProcessOperations");
XmlNode root = conn.EndProcessOperations(result);
processConfirmXML(root);
file.WriteLine("got return XML");
//writeXMLToFile("C:/response.xml",root.InnerXml);
file.WriteLine(root.InnerXml);
// Close the wait handle.
result.AsyncWaitHandle.Close();
}
感谢
保罗
欢迎计算器!通常你不必包含“谢谢”等等或你的名字。我们知道你非常感谢你的帮助,所以这是隐含的,你的名字已经在问题的左下角。 :) – Patrick
哎呀 - 对不起,我没有意识到我忘了它。我重新提出了大约5次的问题,并且必须复制它。 –
在此先感谢所有回复 –