最近研究WCF,希望WCF的服务能够给不同的开发语言调用,测试了Java,遇到这个问题。
首先通过Eclipse 建立一个Web Service Client,引用到WCF服务,会生成以下几个主要文件:
org.tempuri.AuthCommon;
org.tempuri.AuthCommonLocator;
org.tempuri.BasicHttpBinding_IAuthCommonStub;
org.tempuri.IAuthCommon;
org.tempuri. IAuthCommonProxy ;
以为直接 new BasicHttpBinding_IAuthCommonStub 就可以,如下
BasicHttpBinding_IAuthCommonStub serviceStub= new BasicHttpBinding_IAuthCommonStub();
String test = serviceStub.doWork();
结果报了以下错误:
AxisFault
faultCode: {http://xml.apache.org/axis/}Server.NoEndpoint
faultSubcode:
faultString: No endpoint
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}exceptionName:org.apache.axis.NoEndPointException
{http://xml.apache.org/axis/}stackTrace:No endpoint
at org.tempuri.BasicHttpBinding_IAuthCommonStub.doWork(BasicHttpBinding_IAuthCommonStub.java:90)
at cn.iruby.test.TestAuth.main(TestAuth.java:28)
{http://xml.apache.org/axis/}hostname:Yuandh-PC
No endpoint
at org.tempuri.BasicHttpBinding_IAuthCommonStub.doWork(BasicHttpBinding_IAuthCommonStub.java:90)
at cn.iruby.test.TestAuth.main(TestAuth.java:28)
google了一下,原来要这样
AuthCommon service = new AuthCommonLocator();
BasicHttpBinding_IAuthCommonStub serviceStub= (BasicHttpBinding_IAuthCommonStub) service.getBasicHttpBinding_IAuthCommon();
String test = serviceStub.doWork();
OK。