访问Java http Web服务时出现问题. [英] Problem in accessing java http web service.

查看:165
本文介绍了访问Java http Web服务时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否有任何想法在asp.net中调用http(非https)Web服务(带有用于身份验证的用户名和密码)*,而不是SOAP Web服务. Web服务是用Java开发的.因此wsdl.exe将无法通过引用进行其他调用.

这是SOAP UI提取的SOAP信封

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.

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>

推荐答案

如果我没有被误解,您想在Asp中调用基于HTTP的Java Web Service( Servlet ).网.

这也意味着您愿意致电基于 REST 的服务.

尝试按以下代码在您的Asp.Net代码中调用基于REST的服务.
If I am not misunderstood, You want to Call your HTTP based Java Web Service(Servlet) in Asp.Net.

This also means you are willing to call REST based Service.

Try as below code to call REST based Service in your Asp.Net code.
string url = "YourWebServiceUrl";
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

if (response.StatusCode == System.Net.HttpStatusCode.OK)
 {
   System.IO.Stream receiveStream = response.GetResponseStream();
   System.IO.StreamReader readStream = null;

   if (response.CharacterSet == null)
    readStream = new System.IO.StreamReader(receiveStream);
   else
    readStream = new System.IO.StreamReader(receiveStream, 

    System.Text.Encoding.GetEncoding(response.CharacterSet));

    string result = readStream.ReadToEnd();
    response.Close();
    readStream.Close();
}


请查看以下链接,以获取有关 REST 的更多信息.
https://www.ibm.com/developerworks/webservices/library/ws-restful/

http://www.infoq.com/minibooks/emag-03-2010-rest

已更新-

在调用REST服务时,考虑您的Web方法是哪种类型也很重要-获取/发布(暂时不考虑放置和删除).

请参阅下面的文章,其中详细介绍了开发和使用REST服务.
使用C#开发REST Web服务-演练

您可能只看了上一篇文章的"第6部分-测试应用程序"部分,以了解如何调用REST服务的Get/Post Web方法.


Have a look at below links for more information on REST.
https://www.ibm.com/developerworks/webservices/library/ws-restful/

http://www.infoq.com/minibooks/emag-03-2010-rest

Updated -

While calling REST Service, it also important to consider what kind of your Web-Method is - Get/Post(Not considering Put and Delete for now).

Have a look at below Article which elaborates Developing and Consuming REST Services.
Developing a REST Web Service using C# - A walkthrough

You may look at only "Part # 6 - Testing the application" section from above article to understand, How to Call Get/Post Web-Methods of REST Service.


Yahoo终于解决了

Yahoo Finally Solved

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:header xmlns:soap-env="#unknown">" +
            "<ak:password xmlns:ak="#unknown">" + myPassword + "</ak:password>" +
            "<ak:username xmlns:ak="#unknown">" + myUserName + "</ak:username>" +
            "</soap-env:header>" +
            "<soap-env:body xmlns:soap-env="#unknown">" +
                "<ak:vehicle xmlns:ak="#unknown">" +
                "<chassisno>" + sChessisNo + "</chassisno>" +
                "<plateno>" + sPlateNo + "</plateno>" +
                "<platecode>" + sPlateCode + "</platecode>" +
            "" +
            "</ak:vehicle></soap-env:body>" +
        "";


                request.Method = "POST";
                request.ContentType = "application/soap-xml; charset=UTF-8";
                request.Headers.Add("SOAPAction:\"\"");

                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;


这篇关于访问Java http Web服务时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆