Java SOAP 调用 C# 的WebService

Java SOAP 调用 C# 的WebService,C# 的WebService方法的创建可以参考上一篇文章

IntelliJ IDEA Community Edition 2021.2.3的idea64.exe新建项目,导入需要的jar,代码如下:

复制代码
import org.apache.axis.client.Service;
import org.apache.axis.soap.SOAPConstants;
import javax.xml.namespace.QName;
import java.net.URL;

public class Longteng {

    public static void main(String[] args) {
        TestWebserviceHelloWorld3();
    }

    public static void TestWebserviceHelloWorld3() {
        try {
            //String url = "http://localhost:8012/WebService1.asmx";
            //String namespace = "http://tempuri.org/";
            Service service = new Service();
            Call call=(Call)(new Service()).createCall();
            call.setTargetEndpointAddress(new URL("http://localhost:8012/WebService1.asmx"));
            call.setOperationName(new QName("http://tempuri.org/","HelloWorld3"));
            call.setTimeout(30000);
            call.setUseSOAPAction(true);
            call.setSOAPVersion(SOAPConstants.SOAP11_CONSTANTS);
            //解决 提示System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值: 。的错误问题
            // SOAP 1.1 必须添加SOAPAction,SOAP 1.2 则不能添加SOAPAction
            call.setSOAPActionURI("http://tempuri.org/HelloWorld3");
            String re=(String)call.invoke(new String[]{"1","pass"});
            System.out.println(re);

            //Call call=(Call)(new Service()).createCall();
            //call.setTargetEndpointAddress(new URL("http://127.0.0.1:7001/hnCardService/services/CardService"));
            //call.setOperationName(new QName("http://ws.apache.org/axis2","getCard"));
            //call.setTimeout(30000);
            //String re=(String)call.invoke(new String[]{"user","pass","F20000015","420503198104191819","周玉磊","440200"});
            //System.out.println(re);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

    

}
复制代码

测试运行

 

posted @   龙骑科技  阅读(37)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
历史上的今天:
2018-10-23 GZip使用
2017-10-23 层级数据模板 案例(HierarchicalDataTemplateWindow)
2017-10-23 ApplicationCommands 应用程序常见命令
2015-10-23 ObfuscationAttribute模糊处理
点击右上角即可分享
微信分享提示