我有一个从Tibco生成的WSDL,该WSDL可以导入并在SoapUI下运行,即使没有证书也可以连接HTTPS,而没有任何问题,但是尝试使用c#连接到同一端点,我无法使用以下代码连接:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.KeepAlive = true;
req.Accept = "gzip,deflate";
req.Headers.Add("SOAPAction", soapActionHeader);
req.ContentType = "text/xml;charset=UTF-8";
req.Method = "POST";
req.Timeout = requestTimeOut;
#endregion
#region Adding XML body to request
Stream strm = null;
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(xmlSOAPTemplate);
streamWriter.Flush();
streamWriter.Close();
}
#endregion
#region HTTP RESPONSE
string resultValue = string.Empty;
WebResponse resp = req.GetResponse();
strm = resp.GetResponseStream();
StreamReader streamReader = new StreamReader(strm);
string res = streamReader.ReadToEnd();
ExceptionHandler.WriteLog($"{url}:Response:{res}", MethodBase.GetCurrentMethod().Name);
XmlSerializer serializer = new XmlSerializer(typeof(T));
result = (T)serializer.Deserialize(strm);
那么,我们如何解决这个问题?
答案 0 :(得分:0)
您遇到什么错误?
您的代码似乎可以操纵纯HTTP API,而您应该使用通过HTTP调用SOAP的库。
我不是C#程序员,但我在主题上进行了搜索,并找到了此示例(请参见步骤7): https://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/
SOAP可能非常复杂(尤其是如果您使用TIBCO Business Works在其后面带有企业项目的情况下进行生产),则使用HTTP API进行调用会很复杂。