在cpp文件里:
void CMyTreeViewDlg::AddMajor()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service.
Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property["EndPointURL"] = "http://localhost/WS_ELearning/NECServices/WSJiaoWu/AdditionalWS.asmx?wsdl";
Connector->Connect();
//
//
//
//
//
//
//
//
// Begin the message.
//Connector->Property["SoapAction"] = "uri:AddNumbers";
Connector->Property["SoapAction"] = "http://tempuri.org/ELearning/AdditionalWS/ListAllMajorsByObjectID";
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("SOAP","","");
Serializer->StartBody("");
Serializer->StartElement("ListAllMajorsByObjectID ","http://tempuri.org/ELearning/AdditionalWS","","");
Serializer->StartElement("ObjectID","","","");
Serializer->WriteString(L"11");
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
Connector->EndMessage();
Reader.CreateInstance(__uuidof(SoapReader30));
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
_bstr_t result=Reader->RpcResult->text;
MSXML2::IXMLDOMDocumentPtr pXMLDom;
HRESULT hr;
CoInitialize(NULL);
hr = pXMLDom.CreateInstance(__uuidof(DOMDocument40));
if (FAILED(hr))
{
printf("Failed to instantiate DOMDocument40 class/n");
return ;
}
pXMLDom->async = VARIANT_FALSE;
if ( pXMLDom->loadXML(result) != VARIANT_TRUE)
{
printf("Failed load xml data from file./n%s/n",(LPCSTR)pXMLDom->parseError->Getreason());
return ;
}
_bstr_t nodeName="MAJORNAME";
_bstr_t nodeID="MAJORID";
MSXML2::IXMLDOMNodeListPtr pNodeList = pXMLDom->getElementsByTagName(nodeName);
int nList = pNodeList->length;
MSXML2::IXMLDOMNodeListPtr pNodeValueList =pXMLDom->getElementsByTagName(nodeID);
CComboBox *combo=(CComboBox *)this->GetDlgItem(IDC_COMBO1);
for( int n = 0; n < nList; n++ )
{
MSXML2::IXMLDOMNodePtr pNode = pNodeList->item[n];
MSXML2::IXMLDOMNodePtr pNodeValue = pNodeValueList->item[n];
bstr_t bsNodeText = pNode->text;
//CString *buf;
bstr_t bsNodeValue=pNodeValue->text ;
// buf=(CString *)pNodeValue->text ;
BSTR bstrValue = ::SysAllocString(bsNodeValue);
char * buf = _com_util::ConvertBSTRToString(bstrValue);
//buf=bsNodeText;
//combo->AddString("aaa");
//combo->SetDlgItemText(n+1,"111");
//CString aaa="231231";
combo->AddString(bsNodeText);
combo->SetWindowText(buf);
combo->SetDlgItemText(IDC_COMBO1,buf); //SetDlgItemText(IDC_CBO1,str);
//SetItemData(index, data[i].value);
combo->SetItemData(n,(DWORD) buf);
}
combo->SetCurSel(0);
}
然后修改WebService,添加soapRPCMethod()属性,表示采用RPC调用模式,只有这样,才可以在VC里通过soap调用的方法调用,否则调用进来的参数为Nothing。
<SoapRpcMethod(), WebMethod(Description:="通过ObjectID来显示所有的专业")> Public Function ListAllMajorsByObjectID(ByVal ObjectID As String) As String
Dim jwfacade As New NECBusinessFacade.ELearning.JWBusinessFacade.OMGSystem
Dim ds As DataSet = jwfacade.ListMajorsByObjectIDFromMajor(ObjectID, False)
Return ds.GetXml()
End Function