由于深夜还在写代码,所以无法测试.想让大家看看目前的代码 从肉眼的逻辑上看一下 有没有什么一眼发现的问题
代码注释中 带@@@@ 的地方是我拿不准的地方,大家帮忙给看一下
尤其是我webservice的环境部署在网络上.大家帮忙看一下下面代码我疑惑的地方代码主要完成一个功能,webservice中提供了一个GetExpertData(String xx)函数,此函数根据形参返回一个字符串环境部署已安装soap sdk3.0 程序编译无问题 但是运行时抛出
this application has requested the runtime to terminate it in an unusual way please contact the application's support team for more information PS: 这个问题非常严重,究竟是为什么? 麻烦大家帮忙定位一下StdAfx.h中已添加
//WEB_SERVICE
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP30.dll"exclude("IStream","ISequentialStream","_LARGE_INTEGER","_ULARGE_INTEGER","tagSTATSTG","_FILETIME")
using namespace MSSOAPLib30;
//END代码主要为以下void SoapTestDlg::OnOK()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
CString parmater = "CS201103250001";
//连接service
int i=0;
HRESULT hr= CoInitialize(NULL);//初始化com环境写了这句下面才不出错 if(FAILED(hr))
{
i++; //调试是否初始化成功,若失败大多数可能是没有安装SOAPToolkit3.0
AfxMessageBox("rrr");
}
hr=Connector.CreateInstance(__uuidof(HttpConnector30));
if(FAILED(hr))
{
i++;//
AfxMessageBox("eeee");
}
Connector->Property["EndPointURL"] = "http://61.156.8.197:8082/ExpertService.asmx"; //WebService的地址 //写了上句这句不出错服务所在地址和端口
Connector->Connect(); Connector->Property["SoapAction"] = "http://tempuri.org/GetExpertData"; // @@@@这里应该如何填写? or http://61.156.8.197:8082/ExpertService.asmx/GetExpertData or http://61.156.8.197:8082/GetExpertData
Connector->BeginMessage();
Serializer.CreateInstance(__uuidof(SoapSerializer30));
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
Serializer->StartEnvelope("","","");//1
Serializer->EndEnvelope(); Serializer->StartBody("");
Serializer->StartElement("GetExpertData","http://tempuri.org/","NONE",""); // 4 @@@@ //这里应该如何填写?
Serializer->StartElement("parmater","http://tempuri.org/","NONE","");
Serializer->WriteString(_bstr_t(parmater));
Serializer->EndElement(); Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
Connector->EndMessage();
Reader.CreateInstance(__uuidof(SoapReader30));
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
AfxMessageBox((const char*)Reader->RpcResult->text);// 显示收到的结果
CDialog::OnOK();}
代码注释中 带@@@@ 的地方是我拿不准的地方,大家帮忙给看一下
尤其是我webservice的环境部署在网络上.大家帮忙看一下下面代码我疑惑的地方代码主要完成一个功能,webservice中提供了一个GetExpertData(String xx)函数,此函数根据形参返回一个字符串环境部署已安装soap sdk3.0 程序编译无问题 但是运行时抛出
this application has requested the runtime to terminate it in an unusual way please contact the application's support team for more information PS: 这个问题非常严重,究竟是为什么? 麻烦大家帮忙定位一下StdAfx.h中已添加
//WEB_SERVICE
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP30.dll"exclude("IStream","ISequentialStream","_LARGE_INTEGER","_ULARGE_INTEGER","tagSTATSTG","_FILETIME")
using namespace MSSOAPLib30;
//END代码主要为以下void SoapTestDlg::OnOK()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
CString parmater = "CS201103250001";
//连接service
int i=0;
HRESULT hr= CoInitialize(NULL);//初始化com环境写了这句下面才不出错 if(FAILED(hr))
{
i++; //调试是否初始化成功,若失败大多数可能是没有安装SOAPToolkit3.0
AfxMessageBox("rrr");
}
hr=Connector.CreateInstance(__uuidof(HttpConnector30));
if(FAILED(hr))
{
i++;//
AfxMessageBox("eeee");
}
Connector->Property["EndPointURL"] = "http://61.156.8.197:8082/ExpertService.asmx"; //WebService的地址 //写了上句这句不出错服务所在地址和端口
Connector->Connect(); Connector->Property["SoapAction"] = "http://tempuri.org/GetExpertData"; // @@@@这里应该如何填写? or http://61.156.8.197:8082/ExpertService.asmx/GetExpertData or http://61.156.8.197:8082/GetExpertData
Connector->BeginMessage();
Serializer.CreateInstance(__uuidof(SoapSerializer30));
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
Serializer->StartEnvelope("","","");//1
Serializer->EndEnvelope(); Serializer->StartBody("");
Serializer->StartElement("GetExpertData","http://tempuri.org/","NONE",""); // 4 @@@@ //这里应该如何填写?
Serializer->StartElement("parmater","http://tempuri.org/","NONE","");
Serializer->WriteString(_bstr_t(parmater));
Serializer->EndElement(); Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
Connector->EndMessage();
Reader.CreateInstance(__uuidof(SoapReader30));
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
AfxMessageBox((const char*)Reader->RpcResult->text);// 显示收到的结果
CDialog::OnOK();}
POST /ExpertService.asmx HTTP/1.1
Host: 61.156.8.197
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost/GetExpertData"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetExpertData xmlns="http://localhost/">
<RegistrationNo>string</RegistrationNo>
</GetExpertData>
</soap:Body>
</soap:Envelope>HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetExpertDataResponse xmlns="http://localhost/">
<GetExpertDataResult>string</GetExpertDataResult>
</GetExpertDataResponse>
</soap:Body>
</soap:Envelope>由此得知,传入一个字符串,服务器返回的也是一个字符串代码已更新如下[code=C/C++]
void SoapTestDlg::OnOK()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
//连接service
int i=0;
HRESULT hr= CoInitialize(NULL);//初始化com环境写了这句下面才不出错 if(FAILED(hr))
{
i++; //调试是否初始化成功,若失败大多数可能是没有安装SOAPToolkit3.0
AfxMessageBox("rrr");
}
hr=Connector.CreateInstance(__uuidof(HttpConnector30));
if(FAILED(hr))
{
i++;//
AfxMessageBox("eeee");
}
Connector->Property["EndPointURL"] = "http://61.156.8.197:8082/ExpertService.asmx"; //写了上句这句不出错服务所在地址和端口
Connector->Connect(); Connector->Property["SoapAction"] = "http://61.156.8.197:8082/GetExpertData"; // or http://61.156.8.197:8082/ExpertService.asmx/GetExpertData or http://61.156.8.197:8082/GetExpertData
Connector->BeginMessage();
Serializer.CreateInstance(__uuidof(SoapSerializer30));
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
Serializer->StartEnvelope("soap","","");//1
Serializer->StartBody("");
Serializer->StartElement("GetExpertData","http://61.156.8.197:8082/","","soap"); // 4
Serializer->StartElement("RegistrationNo","","","soap"); // 4
Serializer->WriteString("CS201103250001");
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndBody();
Serializer->EndEnvelope();
Connector->EndMessage();
Reader.CreateInstance(__uuidof(SoapReader30));
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
AfxMessageBox((const char*)Reader->RpcResult->text);// 显示收到的结果
CDialog::OnOK();
}但是目前返回的结果却是.... soap-client 。 并不是真正从服务器返回的值..不过侧面说明已经调通了,大家看看 还有什么我没考虑到的。[/code]
To create the DocSample2 low-level C++ client application 1.Open Microsoft® Visual C++ 6.0.
2.On the File menu, select New.
3.Click on the Projects tab, select Win32 Console Application, and, in the Project Name box, enter DocSample2. Click OK.
To add a C++ source file to the DocSample2 application 1.On the File menu, select New.
2.On the Files tab, select C++ Source File and enter a file name. Click OK.
3.Add the following code to this source file. #include <stdio.h>
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;
void Add()
{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service.
Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property["EndPointURL"] = "http://MyServer/Soap3DocSamples/DocSample1/Server/DocSample1.wsdl";
Connector->Connect(); // Begin the message.
//Connector->Property["SoapAction"] = "uri:AddNumbers";
Connector->Property["SoapAction"] = "http://tempuri.org/DocSample1/action/Sample1.AddNumbers";
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("","","");
Serializer->StartBody("");
Serializer->StartElement("AddNumbers","http://tempuri.org/DocSample1/message/","","");
Serializer->StartElement("NumberOne","","","");
Serializer->WriteString("5");
Serializer->EndElement();
Serializer->StartElement("NumberTwo","","","");
Serializer->WriteString("10");
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), ""); // Display the result.
printf("Answer: %s\n", (const char*)Reader->RpcResult->text);
}int main()
{
CoInitialize(NULL);
Add();
CoUninitialize();
return 0;
}
4.Update the value of the EndPointURL property. Specify your server name in the URL.
5.Build and run the application. 最后,我建议你用gSoap,使用方便,调试简单