coodefly 2017-04-07 09:02 采纳率: 0%
浏览 1384
已结题

怎么使用javascript或者ajax去调用C++通过gsoap建立的服务器中的C++接口?

   网上的资料基本都是C++通过gsoap建立服务端,然后通过客户端的方式去访问服务端中的C++接口。

我现在按照网上的一些教程,用C++通过gsoap建立了一个服务器,也生成了相关的wsdl文件。然后我用
C++再通过gsoap建立一个客户端,去调用我服务端的接口,这样的方式是可以调用的。那么问题来了:
我现在不通过建立客户端的方式去调用服务端的接口,我想通过打开网页的方式,在前端中用js(javascript)或者ajax的方式去调用,该怎么调用?我没接触前端,头痛啊,大神求教,SOS急!

这是参考网友的例子生成的wsdl文件:


 <?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/" xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/" xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:HTTP="http://schemas.xmlsoap.org/wsdl/http/" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns="http://tempuri.org/ns.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://tempuri.org/ns.xsd/Service.wsdl" targetNamespace="http://tempuri.org/ns.xsd/Service.wsdl" name="Service">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://tempuri.org/ns.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" targetNamespace="http://tempuri.org/ns.xsd" attributeFormDefault="unqualified" elementFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<!-- operation request element -->
<element name="helloword">
<complexType>
<sequence> </sequence>
</complexType>
</element>
<!-- operation response element -->
<element name="hellowordResponse">
<complexType>
<sequence>
<element name="result" maxOccurs="1" minOccurs="0" type="h-string"/>
<!-- ns__helloword::result -->
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="hellowordRequest">
<part name="Body" element="ns:helloword"/>
<!-- ns__helloword::ns__helloword -->
</message>
<message name="hellowordResponse">
<part name="Body" element="ns:hellowordResponse"/>
</message>
<portType name="ServicePortType">
<operation name="helloword">
<documentation>Service definition of function ns__helloword</documentation>
<input message="tns:hellowordRequest"/>
<output message="tns:hellowordResponse"/>
</operation>
</portType>
<binding name="Service" type="tns:ServicePortType">
<SOAP:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="helloword">
<SOAP:operation soapAction=""/>
<input>
<SOAP:body use="literal" parts="Body"/>
</input>
<output>
<SOAP:body use="literal" parts="Body"/>
</output>
</operation>
</binding>
<service name="Service">
<documentation>gSOAP 2.8.44 generated service definition</documentation>
<port name="Service" binding="tns:Service">
<SOAP:address location="http://localhost:80"/>
</port>
</service>
</definitions>

下面是C++服务器中接口:
int ns__helloword(struct soap*, char **result)
{
    (*result) = "hello world!";
    return SOAP_OK;
}

目的很简单就是想在网页html中调用这个接口。没接触过前端也没接触过java和ajax,js知道一点点,大神们请指点一二啊。
  • 写回答

4条回答 默认 最新

  • coodefly 2017-04-07 09:04
    关注

    第一次发帖,代码好像乱了

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?