VC 访问web service 出错!服务无法处理请求 未将对象引用设置到对象的实例
lza7 2009-02-06 01:49:00 ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service
Connector.CreateInstance(__uuidof(HttpConnector));
//WS服务器地址
Connector->Property["EndPointURL"] = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx";
//连接
Connector->Connect();
//动作
Connector->Property ["SoapAction"] = "http://WebXml.com.cn/qqCheckOnline";
try
{
// Begin message
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("", "", "");
Serializer->startEnvelope("soap", "http://schemas.xmlsoap.org/soap/envelope/", "utf-8");
Serializer->SoapAttribute("xsi", "","http://www.w3.org/2001/XMLSchema-instance","xmlns");
Serializer->SoapAttribute("xsd","","http://www.w3.org/2001/XMLSchema","xmlns");
Serializer->startBody("");
Serializer->startElement("qqCheckOnline","","","");
Serializer->SoapAttribute("xmlns", "http://www.WebXml.com.cn/", "", "");
Serializer->startElement(_bstr_t("qqCode"),"","","");
Serializer->writeString(_bstr_t("251833888"));
Serializer->endElement();
Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();
// Send the message to the web service
Connector->EndMessage();
}
catch (_com_error x) //捕捉异常
{
char *s = new char[56];
strcpy(s,"99");
strcat(s,"向服务器发送信息失败");
delete []s;
}
// Read the response
Reader.CreateInstance(__uuidof(SoapReader));
// Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),"");
Reader->Envelope->text;
// Display the result
if(Reader->Fault != NULL)
{
MSXML2::IXMLDOMElementPtr s = Reader->faultstring;
printf("Fault: %s\n",(const char *)s->text);
}
else
{
printf("Answer: %s\n", (const char *)Reader->RPCResult->xml);
}
运行结果返回错误提示:服务无法处理请求 未将对象引用设置到对象的实例
应该返回"Y"或"N"才对。
请高手赐教!