C# 通过SOAP发布Webservice方法结果

C# 通过SOAP发布Webservice方法结果,c#,winforms,soap,C#,Winforms,Soap,您好,下面是我通过webservice cz.mfcr.adisrws连接的代码(如图所示),我需要根据CreateSoapEnvelope() 使用此代码: namespace spolehlivost_platce { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(obje

您好,下面是我通过
webservice cz.mfcr.adisrws连接的代码(如图所示),我需要根据
CreateSoapEnvelope()

使用此代码:

 namespace spolehlivost_platce
 {
  public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        CallWebService();

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    public static XmlDocument CreateSoapEnvelope()
    {
        XmlDocument soapEnvelop = new XmlDocument();
        soapEnvelop.LoadXml
            (@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""><soapenv:Body><StatusNespolehlivyPlatceRequest xmlns=""http://adis.mfcr.cz/rozhraniCRPDPH/""><dic>28156609</dic></StatusNespolehlivyPlatceRequest></soapenv:Body></soapenv:Envelope>");
        return soapEnvelop;
    }

    protected virtual WebRequest CreateRequest(ISoapMessage soapMessage)
    {
        var wr = WebRequest.Create(soapMessage.Uri);
        wr.ContentType = "text/xml;charset=utf-8";
        wr.ContentLength = soapMessage.ContentXml.Length;

        wr.Headers.Add("SOAPAction", soapMessage.SoapAction);
        wr.Credentials = soapMessage.Credentials;
        wr.Method = "POST";
        wr.GetRequestStream().Write(Encoding.UTF8.GetBytes(soapMessage.ContentXml), 0, soapMessage.ContentXml.Length);

        return wr;
    }
    private static HttpWebRequest CreateWebRequest(string url, string action)
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        webRequest.Headers.Add("SOAPAction", action);
        webRequest.ContentType = "text/xml;charset=\"utf-8\"";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;
    }

    private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
    {
        using (Stream stream = webRequest.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }
    }
    public static void CallWebService()
    {
        var _url = "http://schemas.xmlsoap.org/soap/envelope/"; //issue
        var _action = cz.mfcr.adisrws.InformaceOPlatciType(); //issue 

        XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
        HttpWebRequest webRequest = CreateWebRequest(_url,_action);
        InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

        // begin async call to web request.
        IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

        // suspend this thread until call is complete. You might want to
        // do something usefull here like update your UI.
        asyncResult.AsyncWaitHandle.WaitOne();

        // get the response from the completed web request.
        string soapResult;
        using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
        {
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
            {
                soapResult = rd.ReadToEnd();
            }
            Console.WriteLine(soapResult);
        }

    }
有人能帮我解决这个问题吗

提前谢谢

我收到这个例外:

The remote server returned an error: (405) Method Not Allowed 

我遵循了教程

\u url
是服务的url-是您托管服务的url(“地址”)-如果您自己托管,它可能类似于:

\uURL=”http://localhost/MyService/MyService.asmx“

或者,如果您正在使用其他人已经托管的服务,那么您必须查看他们为其提供的URL,并将该值输入。当前使用的值(
http://schemas.xmlsoap.org/soap/envelope/
)只是数据模式的一种布局,不是实际的URL,尤其不是服务本身(可能会因为http而混淆,但它只是“描述”数据的一种方式)

\u操作
部分-这是您试图调用的服务上的方法,它也应该是字符串,例如:

\u操作=”http://localhost/MyService/MyService.asmx?op=HelloWorld“


你必须考虑你想要实现什么,谁做了什么,在哪里

\u url
是服务的url-是您托管服务的url(“地址”)-如果您自己托管,它可能类似于:

\uURL=”http://localhost/MyService/MyService.asmx“

或者,如果您正在使用其他人已经托管的服务,那么您必须查看他们为其提供的URL,并将该值输入。当前使用的值(
http://schemas.xmlsoap.org/soap/envelope/
)只是数据模式的一种布局,不是实际的URL,尤其不是服务本身(可能会因为http而混淆,但它只是“描述”数据的一种方式)

\u操作
部分-这是您试图调用的服务上的方法,它也应该是字符串,例如:

\u操作=”http://localhost/MyService/MyService.asmx?op=HelloWorld“


你必须考虑你想要实现什么,谁做了什么,在哪里

您好,我更新了服务器。请问应该采取什么措施?我不知道如何创建它。我将非常感谢你。请编辑:我想我知道了,我可以问一下如何显示结果吗?我在sopaResult上收到空值,你能帮我吗?空值可以是很多事情-你必须一步一步地进行调试,看看是否一切都是你所期望的(对你使用的每个变量做一个练习-“我希望这是…”)。。。别误会我的意思,但我认为你不明白你在这里做什么,一旦你明白了,你就会看到错误。。。我们很难仅仅通过查看“调试”其他人的代码。我想多帮点忙,但我不能……你完全正确,我不知道我在做什么。我以前从未经历过这种情况。因为我收到了web服务url和一个调用示例(xml)。我非常感谢你,你是一个很棒的人。再次感谢。您好,我更新了服务器。请问应该采取什么措施?我不知道如何创建它。我将非常感谢你。请编辑:我想我知道了,我可以问一下如何显示结果吗?我在sopaResult上收到空值,你能帮我吗?空值可以是很多事情-你必须一步一步地进行调试,看看是否一切都是你所期望的(对你使用的每个变量做一个练习-“我希望这是…”)。。。别误会我的意思,但我认为你不明白你在这里做什么,一旦你明白了,你就会看到错误。。。我们很难仅仅通过查看“调试”其他人的代码。我想多帮点忙,但我不能……你完全正确,我不知道我在做什么。我以前从未经历过这种情况。因为我收到了web服务url和一个调用示例(xml)。我非常感谢你,你是一个很棒的人。再次感谢。
The remote server returned an error: (405) Method Not Allowed