在没有 wsdl 的情况下调用 Web 服务会导致"500 - Internal Server Error."



我有一个地址:https://103.9.200.73/DPWS_GIP 提供...(提供什么?....我想构建一个类似的 Web 服务。当我使用 Firefox 打开该链接时,服务器正在响应:

<env:Envelope>
    <env:Body>
        <env:Fault>
            <faultcode>env:Client</faultcode>
            <faultstring>Internal Error</faultstring>
        </env:Fault>
    </env:Body>
</env:Envelope>

我不得不灼烧并参考主题:

  1. 如何在 .NET 中调用没有 wsdl 的 Web 服务

我想提供的一些图像 - 请指定图像显示的内容!

如果我运行我的 Web 服务:远程服务器在代码行返回错误:(500) 内部服务器错误":using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

我的网络服务的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections.Specialized;

namespace WSHelloWord
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]   
    public class WebService1 : System.Web.Services.WebService
    {
        [WebMethod]
        public void PostXml(string url)
        {
            string xml = @"<?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><HelloWorld3 xmlns=""http://tempuri.org/""><parameter1>test</parameter1><parameter2>23</parameter2><parameter3>test</parameter3></HelloWorld3></soap:Body></soap:Envelope>";
            byte[] bytes = Encoding.UTF8.GetBytes(xml);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentLength = bytes.Length;
            request.ContentType = "text/xml";
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    string message = String.Format("POST failed with HTTP {0}",
                                                   response.StatusCode);
                    throw new ApplicationException(message);
                }
            }
        }
    }
}

最新更新