【问题标题】:Calling web service without wsdl results in "500 - Internal Server Error."在没有 wsdl 的情况下调用 Web 服务会导致“500 - 内部服务器错误”。
【发布时间】:2015-03-12 08:20:52
【问题描述】:

我有一个地址:https://103.9.200.73/DPWS_GIP 提供...(提供什么?)... 的第三方网络服务。我想建立一个类似的网络服务。 当我使用 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

SOME IMAGE I WANT TO PROVIDE - please specify what the image shows!

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

【问题讨论】:

  • 我已尝试编辑您的问题,使其更易于理解。但是有一些信息缺失,所以请提供它们。另请提供您的服务器的堆栈跟踪。
  • 嗨,Marvin Emil Brach,
  • (提供什么?)-> 税务总局提供 1 个 Web 服务地址(app.config):103.9.200.73:444/DPWS_GIP" binding="basicHttpBinding" bindingConfiguration="GIP_WSPortBinding" 合同="TCTService.GIP_WS" name="GIP_WSPort" />
  • 我不知道税务总局的 WebService 代码,因为他们不为我提供源代码。我想在本地调用没有 wsdl 或 asmx 的 webservice:127.0.0.1:2476/WebService1.asmx 当前,我使用 HttpWebRequest 类,但我的代码在 Server Respone:500 处存在错误。我找不到导致此问题的原因.

标签: web-services soap wsdl


【解决方案1】:

我的网络服务代码

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

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 2012-03-29
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 2011-01-22
    相关资源
    最近更新 更多