在没有wsdl的情况下调用Web服务会导致“500 - 内部服务器错误”。

时间:2015-03-12 08:20:53

标签: web-services soap wsdl

我有一个地址: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. How to call a web service with no wsdl in .net
  2. SOME IMAGE I WANT TO PROVIDE - please specify what the image shows!

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

1 个答案:

答案 0 :(得分:0)

我的网络服务代码

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

    }
}