使用 HTTP/1.0 的 Web 服务 HTTP 请求

本文关键字:HTTP Web 服务 请求 使用 | 更新日期: 2023-09-27 18:37:03

>我正在使用 C# 向合作伙伴 Web 服务发送 SOAP 请求,

public class EODReproting : System.Web.Services.WebService
{
    /// <summary>
    /// Execute a Soap WebService call
    /// </summary>
    [WebMethod(MessageName = "SendZRARequest")]
    public void Execute()
    {
            HttpWebRequest request = CreateWebRequest();
            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(@"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ser=""http://service.bank.pmt.zra"" xmlns:xsd=""   http://bean.bank.pmt.zra/xsd"">
                <soapenv:Header/>
                <soapenv:Body>
                <ser:processPaymentNotificationReport>
                <!--Zero or more repetitions:-->
                <ser:pmtNotifyReport>
                <!--Optional:-->
                <xsd:amountPaid>XXXX</xsd:amountPaid>
                <!--Optional:-->
                <xsd:bankBranchCode>XXXXX</xsd:bankBranchCode>
                <!--Optional:-->
                <xsd:bankTransNo>XXXXX</xsd:bankTransNo>
                <!--Optional:-->
                <xsd:datePaid>XXXXXX</xsd:datePaid>
                <!--Optional:-->
                <xsd:paymentRegTransNo>XXXXXX</xsd:paymentRegTransNo>
                <!--Optional:-->
                <xsd:status>S</xsd:status>
                <!--Optional:-->
                <xsd:taxPayerName>BYAN MARTIN</xsd:taxPayerName>
                <!--Optional:-->
                <xsd:tin>1002760252</xsd:tin>
                <!--Optional:-->
            <xsd:transactionId>XXXXXXX</xsd:transactionId>
            </ser:pmtNotifyReport>
        </ser:processPaymentNotificationReport>
    </soapenv:Body>
</soapenv: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();
                }
            }
        }
    }                    
    /// <summary>
    /// Create a soap webrequest to [Url]
    /// </summary>
    /// <returns></returns>
    public HttpWebRequest CreateWebRequest()
    {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://XX.XX.XX.XX:9999/ZraWebService/services/EODPaymentNotificationReportService.EODPaymentNotificationReportServiceHttpSoap11Endpoint/");
            webRequest.Headers.Add("SOAPAction", "urn:processPaymentNotificationReport");
            webRequest.ContentType = "text/xml;charset='"utf-8'"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            webRequest.Proxy = null;
        return webRequest;
    }
  }
}

调用此方法时,我的日志文件夹中记录了错误,

2015.01.09 10:20:25.8485->The remote server returned an error: (500) Internal Server Error.   at      System.Net.HttpWebRequest.GetResponse()
at EODReporting.ZRAEODReproting.Execute()

合作伙伴告诉我使用 HTTP/1.0 发送请求,我想在上面的代码中执行此操作。我该怎么做?

使用 HTTP/1.0 的 Web 服务 HTTP 请求

只需在声明 HttpWebRequest 后添加以下选项:

request.ProtocolVersion=HttpVersion.Version10;