c++调用c#写的webservice服务。参数传递的时候丢了是什么原因?
我用c#调用webservice,参数没丢 我用c++调用的时候,参数传过来就是null 了
这是我写的webservice方法:
[WebMethod]
public string Import( string date)
{
DataChange dataChange = new DataChange();
return dataChange.Import(date); ;
}
我的c++代码如下:
BOOL CWebService::Import(const CString &data,CString &strRet)
{
const CString csMethodName = _T("Import");
const CString csParam1 = _T("data");
BOOL bRet = FALSE;
HRESULT hr = S_FALSE;
ISoapSerializerPtr Serializer;
//CURLEncode urlEncode;
//CString csUrlData;
CString csAction = NAMESPACE_URL;
csAction += csMethodName;
_variant_t vtAction = csAction;
try
{
if (!m_IsConnected)
{
goto End;
}
// Begin the message.
m_Connector->Property[_T("SoapAction")] = vtAction;
hr = m_Connector->BeginMessage();
if (FAILED(hr))
{
goto End;
}
// Create the SoapSerializer object.
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
if (FAILED(hr))
{
goto End;
}
// Connect the serializer object to the input stream of the connector object
hr = Serializer->Init(_variant_t((IUnknown*)m_Connector->InputStream));
if (FAILED(hr))
{
goto End;
}
// Build the SOAP Message.
Serializer->StartEnvelope(_T(""), _T(""), _T(""));
Serializer->StartBody(_T(""));
Serializer->StartElement(_bstr_t(csMethodName), _bstr_t(NAMESPACE_URL) , _T(""),_T(""));
Serializer->StartElement(_bstr_t(csParam1), _bstr_t(NAMESPACE_URL), _T(""), _T(""));
Serializer->WriteString(_bstr_t(data));
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the XML Web service.
hr = m_Connector->EndMessage();
if (FAILED(hr))
{
goto End;
}
BSTR bstData = NULL;
ISoapReaderPtr Reader;
// Read the response.
Reader.CreateInstance(__uuidof(SoapReader30));
// Connect the reader to the output stream of the connector object.
Reader->Load(_variant_t((IUnknown*)m_Connector->OutputStream), _T(""));
//hr = Reader->RPCResult->get_text(&bstData);
hr = Reader->RpcResult->get_text(&bstData);
if (FAILED(hr))
{
goto End;
}
strRet = bstData;
bRet = TRUE;
}
catch(_com_error &e)
{
CString csError = e.ErrorMessage();
CLogger::WriteFormatErrLine(_T("Import is failed:%s \r\n %s"), csError, data);
}
catch (...)
{
}
End:
return bRet ;
}
这个很简单,你抓包分析下 C# 和 C++ 分配发送的请求是什么就知道了。
请问如何抓包,我是把wince中的数据通过webservice导出到服务器上面的。我调试的时候,c++参数有值。但是,传到webservice方法后,webservice方法接受到的参数是null
@艾新草: wince 啊!这你得自己上网搜一个抓包工具了,我不知道。要不你就在服务端抓包,用 Microsoft Network Monitor。
如果解决不了。直接做一个post调教
请详细说一下
你在返回类型前面加个“static"关键词试试