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最好的是附上程序例子
非常感谢大家的帮助!!!
急需解答的问题包括:
1、soap的类型映射(mapping)
2、vc版soap实例的Reader->RPCResult 的返回类型{目前只知道返回字符串型(const char *)Reader->RPCResult->text 我想知道返回数组类型的语法(java中实现起来很方便),而且不想用将数组值连接成一个字符串返回的方式。 谢谢!}
3、vc版soap实例的捕捉错误代码的例子 (fault , java实现起来很方便)
veryvery最好的是附上程序例子
非常感谢大家的帮助!!!
客户端用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;
我用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>
检查一下你的url是否有效
你的服务端用什么写的?
服务端我用的是COM,用MS Soap Toolkit包装成Web Service的。这种服务端效率要比asp.net写的效率高。我以前在客户端用的是一个开源的库写的。现在想用MS的,却不行了……