网上的资料基本都是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知道一点点,大神们请指点一二啊。