使用soap组件发送webs遗留未结问题,soap体的构建费劲
HRESULT hr;
try
{
CComPtr<ISoapConnector> SoapConnector;
//创建SoapConnector类的对象
SoapConnector.CoCreateInstance(CLSID_HttpConnector30);
//指定Web服务的地址
SoapConnector->put_Property(CComBSTR("EndPointURL"),_variant_t("http://172.18.70.32/MobileService"));
//与Web服务连接
hr=SoapConnector->Connect();
//指定Web服务完成的操作
SoapConnector->put_Property(CComBSTR("SoapAction"),_variant_t(_T("http://tempuri.org/IMobileService/GetXY")));
//准备发送消息给Web服务
SoapConnector->BeginMessage();
// 创建SoapSerializer对象
CComPtr<ISoapSerializer> Serializer;
Serializer.CoCreateInstance(CLSID_SoapSerializer30);
// 将serializer连接到connector的输入字符串
IStreamPtr pStream;
SoapConnector->get_InputStream(&pStream);
hr=Serializer->Init(_variant_t((IUnknown*)pStream));
// 创建SOAP消息
hr=Serializer->StartEnvelope(CComBSTR(""),CComBSTR(""),CComBSTR(""));
Serializer->SoapAttribute(CComBSTR("xsi"), CComBSTR(""), CComBSTR("http://www.w3.org/2001/XMLSchema-instance"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("xsd"), CComBSTR(""), CComBSTR("http://www.w3.org/2001/XMLSchema"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("ns3"), CComBSTR(""), CComBSTR("http://schemas.microsoft.com/2003/10/Serialization/"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("ns4"), CComBSTR(""), CComBSTR("http://schemas.datacontract.org/2004/07/PGis110.Helper"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("ns1"), CComBSTR(""), CComBSTR("http://tempuri.org/"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("c14n"), CComBSTR(""), CComBSTR("http://www.w3.org/2001/10/xml-exc-c14n#"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("xenc"), CComBSTR(""), CComBSTR("http://www.w3.org/2001/04/xmlenc#"),CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("wsc"), CComBSTR(""), CComBSTR("http://schemas.xmlsoap.org/ws/2005/02/sc"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("ds"), CComBSTR(""), CComBSTR("http://www.w3.org/2000/09/xmldsig#"),CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("wsse"), CComBSTR(""), CComBSTR("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("chan"), CComBSTR(""), CComBSTR("http://schemas.microsoft.com/ws/2005/02/duplex"),CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("wsa5"), CComBSTR(""), CComBSTR("http://www.w3.org/2005/08/addressing"), CComBSTR("xmlns"));
Serializer->SoapAttribute(CComBSTR("wsu"), CComBSTR(""), CComBSTR("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"),CComBSTR("xmlns"));
hr=Serializer->SoapAttribute(CComBSTR("wst"), CComBSTR(""), CComBSTR("http://schemas.xmlsoap.org/ws/2005/02/trust"), CComBSTR("xmlns"));
hr=Serializer->StartHeader(CComBSTR("NONE"));
hr=Serializer->EndHeader();
Serializer->StartBody(CComBSTR("NONE"));
Serializer->StartElement(CComBSTR("GetXY"),CComBSTR(""),CComBSTR(""),CComBSTR("ns1")); // 消息函数名称
Serializer->StartElement(CComBSTR("phone"),CComBSTR(""),CComBSTR(""),CComBSTR("ns1")); // 函数参数
Serializer->WriteString(CComBSTR("15131040117")); //参数处理
Serializer->EndElement();
hr=Serializer->EndElement();
hr=Serializer->EndBody();
hr=Serializer->EndEnvelope();
//消息真正地发给Web服务
hr= SoapConnector->EndMessage(); //0x80070057, 0x800a1518 现在异常 //1 0x800A13BA BAD_REQUEST 由WSDL程序返回错误
// 搜索到这个错误值, 找到了一个修改方案 修改了注册的表的一个项, 但是还是如此, 可能是webss 为1.2的soap协议吧 猜的,soap体的构建费劲
// 读取响应
CComPtr<ISoapReader> Reader;
Reader.CoCreateInstance(CLSID_SoapReader30);
// Connect the reader to the output stream of the connector object.
IStreamPtr pStream2;
SoapConnector->get_OutputStream(&pStream2);
VARIANT_BOOL bSuc;
Reader->Load(_variant_t((IUnknown *)pStream2, true), CComBSTR(""), &bSuc);
//IXMLDOMElementPtr pDoc;
//Reader->get_Envelope(&pDoc);
// Display the result.
IXMLDOMDocumentPtr pDoc;
Reader->get_Dom(&pDoc);
_bstr_t msg = pDoc->text;
MessageBox((LPCTSTR)msg);
}
catch (_com_error e)
{
_bstr_t bstr = e.Description();
}