1

서비스 참조를 내 ASP .NET 프로젝트에 추가하지 않고 ASP .NET 프로젝트에서 워크 플로 서비스를 호출하려고합니다. 서비스로 추가하지 않고 웹 서비스를 호출하는 방법에 대한 예제를 발견했으며 내 워크 플로 서비스 requeirements에 따라이를 변경했습니다. 작동하게 할 수 있습니까?C# 서비스 추가 참조없이 HttpRequest 호출 워크 플로 서비스

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; 
} 

나는 (@에 "http : // localhost를 : 3724/Service1.xamlx")의 HttpWebRequest WebRequest 클래스 =에 오류 (HttpWebRequest를)이 WebRequest.Create를 얻을 ;. 오류 : 내부 서버 오류입니다. 작동 방식에 대한 아이디어가 있으십니까?

+0

(I 워크 플로 서비스를 생각한다 WCF 서비스가 맞습니까?)? 나중에 비누 봉투를 직접 만들어야하는 번거 로움을 덜어 주며 서비스 참조가 필요하지 않습니다. 이는 더 간단한 접근 방법 일 수 있습니다. – kmp

답변

1

이전에 WCF를 사용하지 않은 날에 필자는 자체 생성 된 웹 서비스 참조 프록시 (일명 reference.cs)의 코드를 추출하여 내 클라이언트 프록시 클래스를 제어했습니다. 결과는 (가독성 죄송합니다)에 WS의 GetRessource 메소드를 호출 다음 클래스처럼 보였다 : 당신의 HttpWebRequest를 사용해야하고 ChannelFactory에 사용할 수 없습니다 이유가 있나요

[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; 
     } 
    }    
} 
관련 문제