如何在 C# 中使用 SOAP Web 服务,响应时出现错误 500

本文关键字:响应 错误 服务 Web SOAP | 更新日期: 2023-09-27 18:34:51

我正在使用http的Web服务,它是基于肥皂的服务,在响应时它给出错误使用 http 代码 500 .知道为什么会这样吗?

soap body is as 

查询名称可用性请求

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:uri="uri:v2.external.query.name.availability.asic.gov.au" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:uri1="uri:business.document.header.types.asic.gov.au" xmlns:uri2="uri:fss.types.asic.gov.au" xmlns:uri3="uri:types.asic.gov.au" xmlns:uri4="uri:nni.types.asic.gov.au">
   <soap:Header/>
   <soap:Body>
      <uri:request>
         <uri1:businessDocumentHeader>
            <uri1:messageType>queryNameAvailability</uri1:messageType>
            <uri1:messageReferenceNumber>cnr 1</uri1:messageReferenceNumber>
            <uri1:messageVersion>2</uri1:messageVersion>
            <uri1:senderId>234</uri1:senderId>
            <uri1:senderType>REGA</uri1:senderType>
         </uri1:businessDocumentHeader>
         <uri:businessDocumentBody>
            <uri4:proposedName>CNR</uri4:proposedName>
            <uri4:companyNameAvailabilityCheck>true</uri4:companyNameAvailabilityCheck>
         </uri:businessDocumentBody>
      </uri:request>
   </soap:Body>
</soap:Envelope>

查询名称可用性 CNR 1 3E9527DC-71FA-4103-BBB3-EB8D4221573A 2 专用集成电路 政府 专用集成电路 企业名称 1 2014-12-19T09:08:03 专用集成电路 真 可用 CNR可用。

C# 代码如下

String user = "username";
string pwd = "password";       
NetworkCredential creds = new NetworkCredential(user, pwd);
StreamReader reader = new StreamReader((Server.MapPath("").ToString() + "''XMLFile1.xml").ToString().Replace("Home''",""));
string soap = reader.ReadToEnd();
byte[] bytess = System.Text.Encoding.ASCII.GetBytes(soap); 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.gateway.uat.asic.gov.au/gateway/ExternalQueryNameAvailabilityPortV2?WSDL");
request.Credentials = creds;
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.ContentLength = bytess.Length;
Stream oss = request.GetRequestStream();
oss.Write(bytess, 0, bytess.Length);
WebResponse response = request.GetResponse();

响应时发现服务器错误,代码为 500

知道错误的原因是什么吗?

如何在 C# 中使用 SOAP Web 服务,响应时出现错误 500

在调用服务时,url 不应包含 '?WSDL',因为它只是为了检查服务的细节