1
私は、SOAP Webサービスからの応答を取得しようとしているが、私は応答を得るために、この私のクラスwebexceptionエラー500は、HttpWebRequestのリターンエラー500のGetResponse()
に落ちてる:
public static string getResponse()
{
StringBuilder xml = new StringBuilder();
//xml.Append(@"<?xml version=""1.0"" encoding=""utf-8""?>");
xml.Append(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:br=""http://www.totvs.com.br/br/"" >").Replace(@"\", "");
xml.Append("<soap:Envelope/>");
xml.Append("<soapenv:Body>");
xml.Append("<br:RealizarConsultaSQLAuth>");
xml.Append("<br:codSentenca>GLOBAL_054</br:codSentenca>");
xml.Append("<br:codColigada>0</br:codColigada>");
xml.Append("<br:codAplicacao>V</br:codAplicacao>");
xml.Append("<br:Usuario>xxxx</br:Usuario>");
xml.Append("<br:Senha>xxxx</br:Senha>");
xml.Append("<br:parameters>codcoligada=1;codsistema=V;codusuario=mestre</br:parameters>");
xml.Append("</br:RealizarConsultaSQLAuth>");
xml.Append("</soapenv:Body>");
xml.Append("</soapenv:Envelope>");
string s = getUKMailData(xml.ToString(), "http://xxx.xxxx.com.br:99/xxxx/wsConsultaSQL.asmx");
return s;
}
public static string getUKMailData(string xml, string address)
{
string result = "";
HttpWebRequest request = CreateWebRequest(address);
XmlDocument soapEnvelopeXml = new XmlDocument();
string teste = xml.Replace(@"\", "");
soapEnvelopeXml.LoadXml(teste);
try
{
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
result = soapResult;
}
}
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
}
return result;
}
public static HttpWebRequest CreateWebRequest(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAP:Action");
webRequest.Headers.Add("username", "xxx");
webRequest.Headers.Add("password", "xxx");
// webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
webRequest.PreAuthenticate = true;
webRequest.Credentials = CredentialCache.DefaultCredentials;
return webRequest;
}
誰でも私を助けることができますか?残念なことに私を助けなかった一連の記事を読んでいます。どうもありがとう!
エラー500は、サーバーが何らかの方法で要求を処理する際にエラーが発生したことを意味します。うまく設計されたAPIは、さらなるコードと応答メッセージで何が起こったのかを示します。たとえば、 '500.13'はWebサーバーがビジー状態であることを示します。レスポンスの内容を見ると、「Usuarioの値が無効です」などのメッセージが含まれている可能性があります。私たちがコードを読んだだけで、何が間違っているのか分かりません。 – Equalsk