WebService的Socket通信的问题

yanj20 2008-07-31 10:18:32
因为项目需要,客户需要通过网页实现和远程服务器的通信。大概结构是:

web页面---> WebService----> socket服务器

现在需要在WebService和socket服务器之间建立Socket通信。网页的指令通过调用Webservice来告知socket服务器。

在.Net中如何通过WebService建立与其它设备的Socket连接,进行数据的交互,请大家不吝赐教,或者给个方案也行,我也查了好多网站,发现这方面的信息也不多。

另外,不想通过数据库交互,这样定时作业的方案毕竟效率还是不高的。

在线等,谢谢大家!
...全文
117 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lllxy 2008-08-19
  • 打赏
  • 举报
回复
up
lvshaoqing 2008-07-31
  • 打赏
  • 举报
回复

web页面中使用CGI程序(可以调用WebService的一个通用接口)...


#include <iostream.h>
#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)); //HttpConnector30 失败,无法这样创建Connector,CXX0017 Error :Symbol “HttpConnector30“ not found(摇头、叹气!)
Connector->Property["EndPointURL"] = "http://127.0.0.1/1/Test.asmx"; //这个当然得改成您自己的拉
Connector->Connect();

// Begin the message.
//Connector->Property["SoapAction"] = "uri:AddNumbers";
Connector->Property["SoapAction"] = "http://localhost/1/SetUser";
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("body");
//Serializer->StartElement("ReturnNumber","http://localhost/1/","",""); //这是本地的Web Services,实际中要指定命名空间
Serializer->StartElement("SetUser","http://localhost/1/","","soap");
Serializer->StartElement("us","http://localhost/1/","","soap");

Serializer->StartElement("id","http://localhost/1/","","");
Serializer->WriteString("51");
Serializer->EndElement();
Serializer->StartElement("name","http://localhost/1/","","");
Serializer->WriteString("0.");
Serializer->EndElement();
Serializer->StartElement("passoword","http://localhost/1/","","");
Serializer->WriteString("123456789");
Serializer->EndElement();

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);
printf("Answer: %s\n", (const char*)Reader->Body->xml);
}

int main()
{
CoInitialize(NULL);
Add();
CoUninitialize();
return 0;
}

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧