远程soap服务器端有个com其中一接口是
HRESULT GetTemp([in]BSTR Url,[out,retval]BSTR*Return);
他的实现是
STDMETHODIMP CGetTime::GetTemp(BSTR Url, BSTR *Return)
{
// TODO: Add your implementation code here
*Return = SysAllocString(_T("jones"));
return S_OK;
}
现在在客户端用soap调
#import "c:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" raw_interfaces_only, exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME", "IErrorInfo")
using namespace MSSOAPLib30; //soap的dll
int main(int argc, char* argv[])
{
CoInitialize(NULL);
_variant_t result;
DISPID dispidFn=0;
HRESULT hr;
ISoapClientPtr pSoapClient;
pSoapClient=ISoapClientPtr(__uuidof(SoapClient30));
long lValue=10;
try
{
//连接soap站点
hr=pSoapClient->MSSoapInit(_bstr_t("http://192.168.100.171:8888/SoapTest.WSDL"),
_bstr_t("SoapTest"),_bstr_t("GetTimeSoapPort"),NULL);
if(FAILED(hr))
{
printf("MSSoapInit 失败\r\n");
_com_issue_error(hr);
}
LPOLESTR pServiceName = L"GetTemp"; //得到Com中的GetTemp的方法ID
hr = pSoapClient->GetIDsOfNames(IID_NULL, &pServiceName, 1,
LOCALE_SYSTEM_DEFAULT, &dispidFn);
if(FAILED(hr))
{
printf("GetIDsOfNames 失败\r\n");
}
else
{
TCHAR strData[126]={0};
VARIANT args[1]={0};
args[0].vt = VT_BSTR;
wsprintf(strData,"test");
args[0].bstrVal = _bstr_t(strData).copy(); //传的参数 既BSTR Url ,如果有多个参数 那args[]就是传的参数的数组
EXCEPINFO excepinfo={0};
DISPPARAMS params={0};
params.cArgs = 1;
params.rgvarg= args;
_variant_t result; //返回的是BSTR *Return 即"jones"
UINT uArgErr=0;
//调用GetTemp的方法
hr=pSoapClient->Invoke(dispidFn, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, ¶ms, &result, &excepinfo, NULL);
if(FAILED(hr))
{
printf("Invoke 失败\r\n");
_com_issue_error(hr);
}
else
{
params.rgvarg[0].plVal;
}
}
}
catch(_com_error& e)
{
TCHAR str[205]={0};
wsprintf(str,"%s,%s,%s,%d",e.Source(),e.Description(),
e.ErrorMessage(),e.Error());
}
CoUninitialize();
return 0;
}
好了一个简单的soap调用就完成了.