.Net调用Java编写的WebServices返回值为Null的解决方法(SoapUI工具测试有返回值)

最近在项目中与别的公司对接业务,对方是Java语言,需要调用对方的WebServices,结果常规的添加web引用的方法可以传过去值,但是返回值为null

查了很多资料,没有解决方法

思考应该是.Net封装后,转换成.Net变量时有问题

于是考虑采用基础的HttpWebRequest,使用Soap协议进行WebServices调用

            try
            {
                Console.WriteLine("新开始进行连接测试");

                string responseString;
                string param = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
                                 <soap12:Body>
                                    <HelloWorld xmlns=""http://tempuri.org/"">
                                        <StudentName>1212</StudentName>
                                         <PassWord>12121</PassWord>
                                    </HelloWorld>
                                </soap12:Body>
                            </soap12:Envelope>";

                byte[] bs = Encoding.UTF8.GetBytes(param);
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("  http://fox-gaolijun/Short_Message/Service1.asmx");
                
                myRequest.Method = "POST";
                myRequest.ContentType = "application/soap+xml; charset=utf-8";
                myRequest.ContentLength = bs.Length;
                
                Console.WriteLine("完成准备工作");

                using (Stream reqStream = myRequest.GetRequestStream())
                {
                    reqStream.Write(bs, 0, bs.Length);
                }
                
                using (HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse())
                {
                    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                    responseString = sr.ReadToEnd();
                    Console.WriteLine("反馈结果" + responseString);
                }
                Console.WriteLine("完成调用接口");
            }
            catch (Exception e)
            {
                Console.WriteLine(System.DateTime.Now.ToShortTimeString() + "LBS EXCEPTION:" + e.Message);
                Console.WriteLine(e.StackTrace);
            }

注意多线程的时候可以参考下面的文章进行优化

https://blog.csdn.net/superhoy/article/details/18598835

 

参考文章:

http://www.cnblogs.com/macroxu-1982/archive/2009/12/23/1630415.html

转载于:https://www.cnblogs.com/leiyongbo/p/10431733.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值