【发布时间】:2011-03-23 00:34:08
【问题描述】:
我正在使用以下代码创建 SOAP 请求
public static string SubmitSoapRequest(string url,
string ns,
string operation,
string requestXml,
bool responseNodeOnly)
{
// make sure the namespace has a trailing slash
ns = ns.TrimEnd('/') + '/';
// format soap request
string soap = string.Format(SOAP_REQUEST_XML, ns, operation, requestXml);
// format soap action
string soapAction = string.Format(@"{0}{1}", ns, operation);
// initialize web request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
// add header and other soap params
req.Headers.Add("SOAPAction", soapAction);
req.ContentType = @"text/xml;charset=""utf-8""";
req.Accept = "text/xml";
req.Method = "POST";
// make soap request
using (Stream s = req.GetRequestStream())
using (StreamWriter sw = new StreamWriter(s))
sw.Write(soap);
// get response from remote web-service
WebResponse response = req.GetResponse();
从已编译的 Windows 应用程序运行时可以正常工作,但从 Windows 服务调用时会失败。从异常中捕获了“500 内部服务器错误”。
是否有任何原因导致通过 Windows 服务运行可能会导致这种情况?
提前感谢您的任何帮助/建议
【问题讨论】: