我正在尝试从 ASP .NET 项目调用工作流服务,而不向我的 asp .net 项目添加服务引用。我找到了一个关于如何在不将其添加为服务的情况下调用 Web 服务的示例,并根据我的工作流服务要求对其进行了更改。有可能让它工作吗?
public void Execute()
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<GetData xmlns=""http://tempuri.org/IService/GetData"">
<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/"">test1234</string>
</GetData>
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
public HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:3724/Service1.xamlx");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
我在 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:3724/Service1.xamlx"); 上收到错误消息。错误:内部服务器错误。关于如何使其工作的任何想法?