异构客户端访问AXIS的返回值,怎么实现呢?

vinci 2006-03-07 11:19:08
例如,客户端用MS SoapToolkit3.0,而WebService采用Tomcat+axis

怎么返回一个自定义的类型?而且MS SoapToolkit也能接收到并能够解析

代码如下:
public class Login{
class UserConfig{
private String liveNum;
public String getLiveNum()
{
return this.liveNum;
}

public void setLiveNum(String _liveNum)
{
this.liveNum = _liveNum;
}
}
public Boolean Login(String username, String password){
return true;
}

public UserConfig GetUserConfig(String username){
UserConfig config = new UserConfig();
config.setLiveNum("1");
return config;
}
}

以上代码在编译后提示:
无法显示网页
您要访问的网页有问题,无法显示。

--------------------------------------------------------------------------------

...全文
141 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
li_d_s 2006-03-08
  • 打赏
  • 举报
回复
用vc调用不用搞的那么麻烦的,用gsoap生成客户端代码,很快搞定的说
vinci 2006-03-08
  • 打赏
  • 举报
回复
Server端采用AXIS,客户端采用VC来调用。
客户端需要返回自定义类型的数据,一直无法正常调用成功,如果返回非自定义的数据则可以调用成功

在Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");时总是出错
怎么解决呢?

详细代码如下:
服务器端
//////////////////////////////////////////////////
//DataServices.jws
import sms.*;
import java.util.HashMap;

public class DataServices {
public Data buildData(String address,String aouthor ){
Data data=new Data();
data.setAddress(address) ;
data.setAouthor(aouthor) ;
HashMap map=new HashMap();
map.put("key1","value1") ;
map.put("key2","value2") ;
map.put("key3","value3") ;
data.setMap(map);
return data;
}
}

//Data.java
package sms;

import java.util.HashMap;

public class Data {
private String author=null;
private String address=null;
private HashMap hmap=null;
public Data() {
}

public String getAddress(){
return address;
}
public void setAddress(String address){
this.address=address;
}

public String getAouthor(){
return author;
}
public void setAouthor(String author){
this.author=author;
}

public HashMap getHMap(){
return hmap;
}
public void setHMap(HashMap map){
this.hmap=map;
}
}

//客户端代码
//////////////////////////////////////////////////////
void CTestSoapClientDlg::CallService()
{
try{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;

// Connect to the service
if(FAILED(Connector.CreateInstance(__uuidof(HttpConnector30)))){
AfxMessageBox("Create HTTP Connector Failed!");
return;
}
Connector->Property["EndPointURL"] = "http://127.0.0.1:8000/axis/DataServices.jws?wsdl";
Connector->Connect();

// Begin message
Connector->Property["SoapAction"] = "";
Connector->BeginMessage();

// Create the SoapSerializer
if(FAILED(Serializer.CreateInstance(__uuidof(SoapSerializer30)))){
AfxMessageBox("Create SOAP Serializer Failed!");
return;
}

// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// Build the SOAP Message
Serializer->StartEnvelope("","","");
Serializer->StartBody("");

Serializer->StartElement("hello","http://DefaultNamespace","","");

Serializer->StartElement("address","","","");
Serializer->WriteString("test");
Serializer->EndElement();

Serializer->StartElement("aouthor","","","");
Serializer->WriteString("qinws");
Serializer->EndElement();

Serializer->EndElement();
char buf[4096];

Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the web service
Connector->EndMessage();

// Let us read the response
if(FAILED(Reader.CreateInstance(__uuidof(SoapReader30)))){
AfxMessageBox("Create SOAP Reader Failed!");
return;
}

// Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");

// Display the result
try{
IXMLDOMElementPtr elm = Reader->GetRpcResult();
VARIANT_BOOL hasChild;
IXMLDOMNodePtr pNode;
BSTR bstrName, bstrText;
if(elm->hasChildNodes(&hasChild))
{
IXMLDOMNodeListPtr nodes;
elm->get_childNodes(&nodes);
long lNodeLen;
nodes->get_length(&lNodeLen);
for(int i = 0; i < lNodeLen; ++i)
{
nodes->get_item(i, &pNode);
pNode->get_nodeName(&bstrName);
pNode->get_text(&bstrText);
sprintf(buf, "%s = %s", (const char*)bstrName,
(const char*)bstrText);
AfxMessageBox(buf);
}
}
}
catch(_com_error& ce)
{
CString str;
str.Format("COM Error :(%08X)%s", ce.Error(), ce.ErrorMessage());
AfxMessageBox(str);

}
}
catch(_com_error& ce)
{
CString str;
str.Format("COM Error :(%08X)%s", ce.Error(), ce.ErrorMessage());
AfxMessageBox(str);
return;
}
}

vinci 2006-03-07
  • 打赏
  • 举报
回复
老兄,给个详细的例子,

能返回自定义格式的数据
开发者开聊 2006-03-07
  • 打赏
  • 举报
回复
HTML Components (HTC) +JS
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp
http://www.codeguru.com/csharp/csharp/cs_webservices/tutorials/article.php/c7781__1/
使用SOAP TOOL KIT
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=D4490E52-5F6E-4127-9DC7-88B7C8F83B74
使用MSXML
http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&DisplayLang=en
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/2334bff1-d389-4c62-a6c0-bc8517aa4cf1.asp
使用COM
使用COM Interop 技术
vinci 2006-03-07
  • 打赏
  • 举报
回复
怎么用Soap Toolkit调用呢?
li_d_s 2006-03-07
  • 打赏
  • 举报
回复
把返回的类型用单独的UserConfig.java来写
vinci 2006-03-07
  • 打赏
  • 举报
回复
是不是返回值设置String,包含XML,
然后客户端自己解析?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧