1

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"); でエラーが発生します。エラー: 内部サーバー エラーです。それを機能させる方法についてのアイデアはありますか?

4

1 に答える 1

1

WCF を使用していなかった時代には、自動生成された Web サービス参照プロキシ (別名 reference.cs) のコードを抽出して、独自のクライアント プロキシ クラスを制御していました。結果は、WS の GetRessource メソッドを呼び出す次のクラスのようになりました (読みにくくて申し訳ありません)。

[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;
        }
    }               
}
于 2012-04-10T10:01:47.297 に答える