我有一个网络服务,我在其中异步发布到 URL
public Response uploadXMLData(string destinationUrl, string requestXml,Request req)
{
try
{
Response resp=new Response();
System.Uri uri = new System.Uri(destinationUrl);
using (WebClient client = new WebClient())
{
client.UploadStringCompleted
+= new UploadStringCompletedEventHandler(UploadStringCallback);
client.UploadStringAsync(uri, "POST",requestXml,req);
}
}
catch (Exception ex)
{}
return resp;
}
public void UploadStringCallback(object sender, UploadStringCompletedEventArgs e)
{
Response resp=new Response();
Request req = new Request();
try
{
if (e.Error != null)
{
object objException = e.Error.GetBaseException();
Type _type = typeof(WebException);
if (_type != null)
{
WebException objErr = (WebException)e.Error.GetBaseException();
WebResponse rsp = objErr.Response;
using (Stream respStream = rsp.GetResponseStream())
{
req= (Request)e.UserState;
resp=Utilities.ParseWithoutSoapEnv(respStream);
}
}
else
{
Exception objErr = (Exception)e.Error.GetBaseException();
throw objErr;
}
}
else
{
//Parse e.Result
}
}
catch (Exception ex)
{}
}
被调用的函数Utilities.ParseWithoutSoapEnv(respStream);
返回类型Response
我想要做的是从该函数获取响应,并将其作为返回值uploadXMLData
但是我无法更改回调函数的返回类型,所以我不知道该怎么做。
当有人调用我的 webservice 函数时,他们希望它返回一个类型Response
,并且Response
我需要的类被接收到 CallBack 函数..
希望我把我的问题说清楚了
任何帮助,将不胜感激