惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
H
Help Net Security
GbyAI
GbyAI
博客园_首页
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
月光博客
月光博客
美团技术团队
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 叶小钗
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed

博客园 - yongwnet

项目开发文档格式 JAVA反射实例 java.util.Properties类 jQuery调用WebService详解 产品经理的素质 Java中实现鼠标模拟与键盘映射 Win7下轻松注册VS2008 Windows7 下的VPC 浅谈项目管理能力的提升 java多态性详解——父类引用子类对象 Java截取字符串的一些常用处理 java类加载的表现形式 extjs COMBOBOX完成类似GOOGLE搜索框(AUTOCOMPLETE) - yongwnet - 博客园 如何有效的压缩VPC虚拟磁盘 VPC 2007 Console界面消失以及解决方法 - yongwnet JAVA匿名实现多线程 - yongwnet - 博客园 java中list类和vector类的比较 JAVA深克隆
JAVA 调用 .NET编写的WebService - yongwnet
yongwnet · 2011-01-21 · via 博客园 - yongwnet

1..NET编写的WebService源码

代码

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
<SoapDocumentService(RoutingStyle:=SoapServiceRoutingStyle.RequestElement)> _
Public Class Service1
    
Inherits System.Web.Services.WebService<WebMethod()> _
   
Public Function HelloWorld(ByVal para_in1 As StringByVal para_in2 As StringAs String
        
Try
            
Dim s As String = "para_in1:" & para_in1.ToString() & ",para_in2=" & para_in2 & vbCrLf
            My.Computer.FileSystem.WriteAllText(
"c:\ws.txt", s, True)
            
Return s
        
Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(
"c:\ws.txt""ex:" & ex.ToString() & vbCrLf, True)
            
Return ex.ToString()
        
End Try
        
Return "NO"End Function
End Class

2.JAVA调用源码:

代码

import javax.xml.namespace.QName;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;public class myMain2 {/**
     * 
@param args
     
*/
    
public static void main(String[] args) {
        
// TODO 自动生成方法存根
        InvokeWebservice();
    }
    
    
public static void InvokeWebservice()
    {
        
try
        {
            
/**说明:
               
               
http://127.0.0.1:4727/Service1.asmx    表示Dotnet的WebService地址
               
http://tempuri.org/     表示命名空间
               HelloWorld             表示调用的函数名
               para_in1                表示 HelloWorld 函数的第一个参数名
               para_in2                表示 HelloWorld 函数的第二个参数名
               
               另:本源码需要引用三个JAR包(axis.jar, jaxrpc.jar, commons-discovery-0.2.jar);
             * 
*/        
            
            String endpoint 
= "http://127.0.0.1:4727/Service1.asmx";
                
            Service service 
= new Service();
    
            Call call 
= (Call) service.createCall();
    
            call.setTargetEndpointAddress(
new java.net.URL(endpoint));            
                    
            call.addParameter(
new QName("http://tempuri.org/","para_in1"), org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
            call.addParameter(
new QName("http://tempuri.org/","para_in2"), org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.Constants.XSD_STRING);
     
            call.setOperationName(
new QName("http://tempuri.org/","HelloWorld"));
            call.setUseSOAPAction(
true);
            call.setSOAPActionURI(
"http://tempuri.org/HelloWorld"); 

            String para_in1 

= "Java_Invoke_DotnetWebservice";
            String para_in2 
= "2011-01-21";
            String s 
= (String)call.invoke(new Object[]{para_in1, para_in2});
    
            System.out.println(
"result is " + s);
            
        }
        
catch (Exception e) 
        {            
            System.err.println(e.toString());
            e.printStackTrace(); 
        }    
    }
    
}

实例下载: Java_Invoke_DotnetWebservice.rar