VC6.0下调用C#编写的WebService存在的问题?
今用C#编写了一个最简单的WebService方法调用:
[WebMethod]
public string HelloWorld(string name)
{
return name;
}
现在VC6.0下采用SOAP Toolkit 3.0调用此接口:
void CSoapDlg::GetReturnVal()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service.
Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property["EndPointURL"]= "http://192.168.1.8/MyService/ServiceList.asmx";
Connector->Connect();
// Begin the message.
Connector->Property[_T("SoapAction")] = _T("http://192.168.1.8/MyService/ServiceList.asmx/HelloWorld");
Connector->BeginMessage();
// Create the SoapSerializer object.
Serializer.CreateInstance(__uuidof(SoapSerializer30));
// Connect the serializer object to the input stream of the connector object.
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Build the SOAP Message.
Serializer->StartEnvelope(_T("HelloWorld"),_T(""),_T(""));
Serializer->StartBody("");
Serializer->StartElement(_T("HelloWorld"),_T("http://192.168.1.8/MyService/ServiceList.asmx/"),
_T(""),_T(""));
Serializer->StartElement("name","","","");
Serializer->WriteString("张");
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the XML Web service.
Connector->EndMessage();
// Read the response.
Reader.CreateInstance(__uuidof(SoapReader30));
// Connect the reader to the output stream of the connector object.
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
MessageBox((const char*)Reader->RpcResult->text);
}
可就是无法得到WebService的返回值,MessageBox里显示的是“soap:Client”的提示信息。