By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
close

Everything about .NET framework.

rss_feed Subscribe RSS

Keywords: .Net , Java EE, Eclipse, Web Services, GlassFish, jws

由于工作的需要,我们的.Net项目需要引用一个java平台下的Web Service 为了便于开发,自己先通过Eclipse建了一个Java的WebService,然后通过Java SDK中自带的GlassFish 服务器发布,然后在.Net项目中添加Web 引用,具体方法如下面所示(由于自己今天第一次学习java 第一次用到Eclipse 所以若有错误请大家见谅):

1,配置Eclipse的Servers

打开Eclipse,在菜单栏的Windows->Preferences 在弹出的对话框中点击Server节点下的Runtime Environments 添加GlassFish 如果没有,点击Add按钮,添加,如果列表中没有GlassFish,那么可以点击链接download additional server adapters 添加GlassFish


添加GlassFish

2,创建Web项目

在菜单栏 File->New->Dynamic Web Project 创建一个动态Web项目 名称为MyJavaWebService,runtime选择刚才配置的GlassFish


3,创建包含一个类HelloWorld


类的代码如下:

package Test;

public class HelloWorld {
public String MyHelloWorld()
{
return "Hello World";

}
}

4,创建WebService

右击刚才创建的HelloWorld.java->Web Services->Create Web Service

点击next 后会生成wsdl文件 以及自动发布到服务器,如果是GlassFish服务器则有可能在Eclipse无法启动服务,如下面,这个时候直接点击Cancel ,我们在以后发布此服务。

这样wsdl就生成好了

这种方法始终出错了,因此采用Tomcat作为服务器,至于解决方法以后再探讨

5,今天早上请教了javawind的唧唧童鞋,终于成功了,不过直接通过Eclipse自带的那种部署却始终不成功,在Tomcat中提示不支持 Webservice,而GlassFish也提示出错无法启动GlassFish的服务器 实际上是启动了的

下面是具体的实现方法:

1)配置web.xml

在<web-app>根节点下添加

<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
</servlet-mapping>
<mime-mapping>
    <extension>wsdl</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>
<servlet>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>

2)将类HelloWorld拷贝至下面WebContent下 并且重命名为HelloWorld.jws,同时去掉命名空间,package Test; 这行


public class HelloWorld {
public String MyHelloWorld()
{
return "Hello World";

}
}
3)导出MyJavaWebService为war

4)在GlassFish中部署这个war

在GlassFish的管理界面->Web 应用程序->点击 部署按钮


点击确定后即可看到部署的war

点击启动即可查看到

点击HelloWorld.jws即可以查看到WebService




点击超链接Click to see WSDL即可查看到Webservice

6,下面我们在.net中调用这个Webservice

http://localhost:8080/MyJavaWebService/HelloWorld.jws?wsdl

1)在.Visual Studio 中新建一个Web项目 TestMyJavaWebService


2)添加web引用 地址为

http://localhost:8080/MyJavaWebService/HelloWorld.jws?wsdl

如下图所示,点击添加引用即可


3)在Default.aspx.cs中添加下面代码

namespace TestMyJavaWebService
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyJavaWebService.HelloWorldService service = new TestMyJavaWebService.MyJavaWebService.HelloWorldService();
            Response.Write(service.MyHelloWorld());
        }
    }
}

点击运行即可查看到效果

至此工作就完成了

info Last modified by Raymond at 7 years ago

info About author

info License/Terms

More from Kontext

local_offer SQL Server local_offer Java local_offer kerberos local_offer NTLM

visibility 1252
thumb_up 0
access_time 10 months ago

With Microsoft SQL Server JDBC driver, you can connect to the database through SQL Server Authentication or Kerberos Authentication. This post summarizes the configurations required for each authentication method with coding examples. *NTLM block in the following diagram represents pure Jav...

open_in_new View

local_offer .NET local_offer dotnet core local_offer spark local_offer parquet local_offer hive

visibility 1092
thumb_up 0
access_time 10 months ago

I’ve been following Mobius project for a while and have been waiting for this day. .NET for Apache Spark v0.1.0 was just published on 2019-04-25 on GitHub. It provides high performance APIs for programming Apache Spark applications with C# and F#. It is .NET Standard complaint and can run in Wind...

open_in_new View

local_offer Java local_offer lite-log local_offer hive

visibility 553
thumb_up 0
access_time 11 months ago

This post shows you how to connect to HiveServer2 via Hive JDBC driver in Java. *The way to connect to HiveServer1 is very similar though the driver names are different: Version D...

open_in_new View

local_offer Java local_offer bigquery local_offer gcp local_offer dataflow local_offer gcs

visibility 5152
thumb_up 1
access_time 2 years ago

This page documents the detailed steps to load CSV file from GCS into BigQuery using Dataflow to demo a simple data flow creation using Dataflow Tools for Eclipse. However it doesn’t necessarily mean this is the right use case for DataFlow. Alternatively ...

open_in_new View

info Follow us on Twitter to get the latest article updates. Follow us