我在 gsoap 客户端 c++ 调用我的简单 wcf 服务时遇到问题,该服务公开:
public double Add(double n1, double n2) {
double result = n1 + n2;
return result;
}
下面是我的 gsoap 客户端测试代码:
BasicHttpBinding_USCORERestaurantService svc;
_ns1__Add request;
_ns1__AddResponse response;
//svc->endpoint
double n1 = 1.12;
double n2 = 2.32;
request.n1 =&n1;
request.n2= &n2;
svc.soap->keep_alive=1;
int iResult = svc.__ns1__Add(&request, &response); // response result always return 0
我在服务上有一个断点,n1,n2 的参数始终为 0;
下面是我的wsdl文件:
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions name="RestaurantService" targetNamespace="http://www.thinktecture.com/services/restaurant/2006/12" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.thinktecture.com/services/restaurant/2006/12" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
<wsdl:types>
<xsd:schema elementFormDefault="qualified" targetNamespace="http://www.thinktecture.com/services/restaurant/2006/12">
<xsd:element name="Add">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="n1" type="xsd:double" />
<xsd:element minOccurs="0" name="n2" type="xsd:double" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AddResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="AddResult" type="xsd:double" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="RestaurantService_Add_InputMessage">
<wsdl:part name="parameters" element="tns:Add" />
</wsdl:message>
<wsdl:message name="RestaurantService_Add_OutputMessage">
<wsdl:part name="parameters" element="tns:AddResponse" />
</wsdl:message>
<wsdl:portType name="RestaurantService">
<wsdl:operation name="Add">
<wsdl:input wsaw:Action="http://www.thinktecture.com/services/restaurant/2006/12/RestaurantService/Add" message="tns:RestaurantService_Add_InputMessage" />
<wsdl:output wsaw:Action="http://www.thinktecture.com/services/restaurant/2006/12/RestaurantService/AddResponse" message="tns:RestaurantService_Add_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_RestaurantService" type="tns:RestaurantService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Add">
<soap:operation soapAction="http://www.thinktecture.com/services/restaurant/2006/12/RestaurantService/Add" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RestaurantService">
<wsdl:port name="BasicHttpBinding_RestaurantService" binding="tns:BasicHttpBinding_RestaurantService">
<soap:address location="http://localhost:3456/WebHost/Service.svc/RS" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
下面是我启用日志记录的肥皂消息:
call from gsoap c++ client
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.thinktecture.com/services/restaurant/2006/12">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:3456/WebHost/Service.svc/RS</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.thinktecture.com/services/restaurant/2006/12/RestaurantService/Add</Action>
</s:Header>
<SOAP-ENV:Body>
<ns1:Add>
<n1 xsi:type="xsd:double" xmlns="">1.1200000000000001</n1>
<n2 xsi:type="xsd:double" xmlns="">2.3199999999999998</n2>
</ns1:Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
从服务返回消息:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="ac83c5fa-e518-4883-a381-f5ec63411226" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">dddc227b-82e3-4578-b282-572017003943</ActivityId>
</s:Header>
<s:Body>
<AddResponse xmlns="http://www.thinktecture.com/services/restaurant/2006/12">
<AddResult>0</AddResult>
</AddResponse>
</s:Body>
</s:Envelope>