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()); } } }
测试运行
龙腾一族至尊龙骑
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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模糊处理