如何捕捉soap连接异常???

trilel 2002-07-30 07:32:59
soap调用的java版,vc版,vb版俺都做通过,不过因为是初学,还有不少问题没搞懂,笨0!! 请高手指教!
急需解答的问题包括:
1、soap的类型映射(mapping)
2、vc版soap实例的Reader->RPCResult 的返回类型{目前只知道返回字符串型(const char *)Reader->RPCResult->text 我想知道返回数组类型的语法(java中实现起来很方便),而且不想用将数组值连接成一个字符串返回的方式。 谢谢!}
3、vc版soap实例的捕捉错误代码的例子 (fault , java实现起来很方便)
veryvery最好的是附上程序例子
非常感谢大家的帮助!!!
...全文
176 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
beegee 2002-08-16
  • 打赏
  • 举报
回复
url是有效的。我通过ie可以直接看到wsdl.会不会的无参数方法的问题?
服务端我用的是COM,用MS Soap Toolkit包装成Web Service的。这种服务端效率要比asp.net写的效率高。我以前在客户端用的是一个开源的库写的。现在想用MS的,却不行了……
beegee 2002-08-15
  • 打赏
  • 举报
回复
对于你的问题2,可以将返回的字符串实际就是IXMLNode,在XML Schema的配合下可以用MSXML parser解析开。

谢谢你的回答!
我用low-level api时遇到了问题。
我的代码是:
...
Connector->Property["EndPointURL"]= "http://localhost:8080/WSMsgSvr.wsdl";
Connector->Connect();

// Begin message
Connector->Property["SoapAction"] = "http://tempuri.org/GetUserList";
Connector->BeginMessage();

// Create the SoapSerializer
Serializer.CreateInstance(__uuidof(SoapSerializer));

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

// Build the SOAP Message
Serializer->startEnvelope("","http://schemas.xmlsoap.org/soap/encoding/","");
Serializer->startBody("");
Serializer->startElement("GetUserList","http://tempuri.org/","","m");
Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();

// Send the message to the web service
Connector->EndMessage();
...
我的Web Service的方法是GetUserList,无参数。结果失败,catch到未知错误。跟踪了一下,是最后一句“Connector->EndMessage();”跳出的。
我哪儿错了?
以下是MSSoapT截获的唯一的SOAP消息:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
- <SOAP-ENV:Body SOAP-ENV:encodingStyle="">
<m:GetUserList xmlns:m="http://tempuri.org/" SOAP-ENV:encodingStyle="" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
trilel 2002-08-15
  • 打赏
  • 举报
回复
“Connector->EndMessage();”跳出异常通常是连接失败错误.
检查一下你的url是否有效
你的服务端用什么写的?
beegee 2002-08-14
  • 打赏
  • 举报
回复
请指教你在VC中soap包的格式和相应VC代码。谢谢!
trilel 2002-08-14
  • 打赏
  • 举报
回复
下面的例子我写的是ASP.net的soap service
客户端用vc调用
用Java编写的soap service也是一样

SOAP消息格式:
所显示的占位符需要由实际值替换。

POST /WebServiceSample/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.wellhope.com/webservices/retstr"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<retstr xmlns="http://www.wellhope.com/webservices">
<instr>string</instr>
</retstr>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<retstrResponse xmlns="http://www.wellhope.com/webservices">
<retstrResult>string</retstrResult>
</retstrResponse>
</soap:Body>
</soap:Envelope>



VC的soap调用部分代码:
char userStr[256]="<instr xsi:type='xsd:string'>qwert</instr>";
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;

// 与Web服务连接
Connector.CreateInstance(__uuidof(HttpConnector));
Connector->Property["EndPointURL"] = "http://localhost/WebServiceSample/Service1.asmx";
long s = Connector->Connect();

// 开始消息
Connector->Property["SoapAction"] = "http://www.wellhope.com/webservices/retstr";
Connector->BeginMessage();

// 创建SoapSerializer对象
Serializer.CreateInstance(__uuidof(SoapSerializer));

// 将serializer连接到connector的输入字符串
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// 创建SOAP消息
Serializer->startEnvelope("ns1","http://schemas.xmlsoap.org/soap/encoding/","");

Serializer->SoapNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
Serializer->SoapNamespace( "xsd", "http://www.w3.org/2001/XMLSchema");

Serializer->startBody("http://schemas.xmlsoap.org/soap/encoding/");
Serializer->startElement("retstr", "http://www.wellhope.com/webservices/retstr","", "soap"); Serializer->writeXML (userStr);
Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();
Connector->EndMessage();
// 读取响应
Reader.CreateInstance(__uuidof(SoapReader));
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),"");
CString strResult;
strResult=(const char *)Reader->RPCResult->text;

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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