如何在Asp.Net中调用基于HTTP的Java Web服务(Servlet)。 [英] How to Call HTTP based Java Web Service(Servlet) in Asp.Net.
本文介绍了如何在Asp.Net中调用基于HTTP的Java Web服务(Servlet)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你有什么想法在asp.net.its而不是SOAP web服务中调用http(而不是https)web服务(用户名和密码进行身份验证)*。 Web服务在java中开发。所以wsdl.exe无法通过引用调用。
Do you hav any idea abt calling http(not https) web service(with username and password for authentication )* in asp.net.its not SOAP web service. Web service is devloped in java. So wsdl.exe won't work nither calling though reference.
这是SOAP UI提取的SOAP信封
this is the SOAP UI extracted SOAP envelop
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ak="http://linkaddress">
<soapenv:Header>
<ak:password>?</ak:password>
<ak:username>?</ak:username>
</soapenv:Header>
<soapenv:Body>
<ak:Vehicle>
<chassisNo>?</chassisNo>
<plateNo>?</plateNo>
<plateCode>?</plateCode>
</ak:Vehicle>
</soapenv:Body>
</soapenv:Envelope>
推荐答案
最后,我解决了我的问题:
Finally, I solve my problem:
string sResponse = string.Empty;
try {
Uri uri = new Uri(sFetchURL);
if (uri.Scheme == Uri.UriSchemeHttp) {
HttpWebRequest request = null;
request = (HttpWebRequest) HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
request.ContentType = "text/xml;charset=\"utf-8\"";
string strSOAPRequestBody = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ak=\"http://Link.JavaService\">" +
"<SOAP-ENV:Header>" +
"<ak:password>" + myPassword + "</ak:password>" +
"<ak:username>" + myUserName + "</ak:username>" +
"</SOAP-ENV:Header>" +
"<SOAP-ENV:Body>" +
"<ak:Vehicle>" +
"<chassisNo>" + sChessisNo + "</chassisNo>" +
"<plateNo>" + sPlateNo + "</plateNo>" +
"<plateCode>" + sPlateCode + "</plateCode>" +
"</ak:passingVehicleTest>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
request.Method = "POST";
request.ContentType = "application/soap-xml; charset=UTF-8";
request.Headers.Add("SOAPAction:\"\"");//please check RAW data In SOAP UI
request.ContentLength = strSOAPRequestBody.Length;
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(
request.GetRequestStream());
streamWriter.Write(strSOAPRequestBody);
streamWriter.Close();
System.IO.StreamReader streamReader = new System.IO.StreamReader(
request.GetResponse().GetResponseStream());
while (!streamReader.EndOfStream)
sResponse += streamReader.ReadLine();
}
} catch (WebException err) {
HttpWebResponse httpResponse = null;
httpResponse = (HttpWebResponse) err.Response;
Stream baseStream = httpResponse.GetResponseStream();
System.IO.StreamReader streamReader2 = new System.IO.StreamReader(
baseStream);
while (!streamReader2.EndOfStream)
sResponse += streamReader2.ReadLine();
}
return sResponse;
这篇关于如何在Asp.Net中调用基于HTTP的Java Web服务(Servlet)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文