c#通过HttpRequest调用工作流服务而不添加服务引用
我正在尝试从ASP.NET项目调用工作流服务,而不向ASP.NET项目添加服务引用。我找到了一个关于如何调用web服务而不将其添加为服务的示例,并根据工作流服务要求对其进行了更改。有可能使它工作吗c#通过HttpRequest调用工作流服务而不添加服务引用,c#,workflow-foundation,workflow-foundation-4,workflowservice,C#,Workflow Foundation,Workflow Foundation 4,Workflowservice,我正在尝试从ASP.NET项目调用工作流服务,而不向ASP.NET项目添加服务引用。我找到了一个关于如何调用web服务而不将其添加为服务的示例,并根据工作流服务要求对其进行了更改。有可能使它工作吗 public void Execute() { HttpWebRequest request = CreateWebRequest(); XmlDocument soapEnvelopeXml = new XmlDocument(); soapEnvelopeXml.L
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;
}
public void Execute()
{
HttpWebRequest请求=CreateWebRequest();
XmlDocument soapEnvelopeXml=新的XmlDocument();
soapEnvelopeXml.LoadXml(@)
测试1234
");
使用(Stream=request.GetRequestStream())
{
soapEnvelopeXml.Save(流);
}
使用(WebResponse=request.GetResponse())
{
使用(StreamReader rd=newstreamreader(response.GetResponseStream())
{
字符串soapResult=rd.ReadToEnd();
控制台写入线(soapResult);
}
}
}
公共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”;
返回webRequest;
}
我在HttpWebRequest webRequest=(HttpWebRequest)webRequest上收到一个错误。创建(@)http://localhost:3724/Service1.xamlx");. 错误:内部服务器错误。
有什么办法让它工作吗 在我没有使用WCF的时候,我曾经提取自动生成的webservice引用代理(aka reference.cs)的代码来控制我自己的客户端代理类。 结果类似于调用WS的GetRessource方法的以下类(为可读性感到抱歉):
在我没有使用WCF的时候,我曾经提取自动生成的webservice引用代理(aka reference.cs)的代码来控制我自己的客户端代理类。 结果类似于调用WS的GetRessource方法的以下类(为可读性感到抱歉):
您需要使用HttpWebRequest而不能使用ChannelFactory(我认为工作流服务只是WCF服务,对吗?)?后者将使您无需手动构建soap信封,并且不需要服务引用,这可能是一种更简单的方法。您是否有理由需要使用HttpWebRequest而不能使用ChannelFactory(我认为工作流服务只是WCF服务,对吗?)?后者将使您无需手动构建soap信封,并且不需要服务引用,这可能是一种更简单的方法。
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.42")]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlInclude(typeof(Ressource))]
[System.Web.Services.WebServiceBindingAttribute(Name = "WSSoap", Namespace = "http:/tempuri.org/Web/WS/WS.asmx")]
public class RemoteManager : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public RemoteManager() {
this.Url = "http://localhost/web/WS/WS.asmx";
if ((this.IsLocalFileSystemWebService(this.Url) == true))
{
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else
{
this.useDefaultCredentialsSetExplicitly = true;
}
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http:/tempuri.org/Web/WS/WS.asmx/" +
"GetRessource", RequestElementName = "GetRessource", RequestNamespace = "http:/tempuri.org/Web/WS/WS.asmx", ResponseElementName = "GetRessourceResponse", ResponseNamespace = "http:/tempuri.org/Web/WS/WS.asmx", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("GetRessourceResult")]
public Ressource GetRessource(int ressId)
{
object[] results = this.Invoke("GetRessource", new object[] {
ressId});
return ((Ressource)(results[0]));
}
public new string Url
{
get
{
return base.Url;
}
set
{
if ((((this.IsLocalFileSystemWebService(base.Url) == true)
&& (this.useDefaultCredentialsSetExplicitly == false))
&& (this.IsLocalFileSystemWebService(value) == false)))
{
base.UseDefaultCredentials = false;
}
base.Url = value;
}
}
private bool useDefaultCredentialsSetExplicitly;
public new bool UseDefaultCredentials
{
get
{
return base.UseDefaultCredentials;
}
set
{
base.UseDefaultCredentials = value;
this.useDefaultCredentialsSetExplicitly = true;
}
}
}