gsoap2.8客户端和wcf服务() 我对GSOAP客户机C++调用发出了一个简单的WCF服务,它暴露了: public double Add(double n1, double n2) { double result = n1 + n2; return result; }
下面是我的gsoap客户端测试代码:gsoap2.8客户端和wcf服务() 我对GSOAP客户机C++调用发出了一个简单的WCF服务,它暴露了: public double Add(double n1, double n2) { double result = n1 + n2; return result; },wcf,gsoap,Wcf,Gsoap,下面是我的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
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>
下面是我启用日志记录的soap消息:
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>
<代码>从gSOAP C++客户端调用
http://localhost:3456/WebHost/Service.svc/RS
http://www.thinktecture.com/services/restaurant/2006/12/RestaurantService/Add
1.1200000000000001
2.3199999999999998
从服务返回消息:
<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>
dddc227b-82e3-4578-b282-572017003943
0
当WCF服务总是在请求添加时返回0(int n1,int n2)时,我也有同样的问题。经过长时间的工作,我找到了解决方案,我的解决方案是应用gSoap 2.7.16而不是上一个2.8.1_2,它工作得完美无缺。下班后,我已经解决了这个问题,如果您使用WCF,您需要在操作中添加一个属性,例如:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Literal)]
long Method1(int a, int b, long c, string d);
}
因此,gsoap可以将参数值正确地发送到服务器。我有一种预感,这与名称空间有关。尝试删除请求中n1和n2的“xmlns=”“”(例如,使用Fiddler截取并更改请求),然后查看是否有任何更改。感谢Eugene的帮助。我能够比较soap2.8下面的2.7和2.8的soap头消息:1.1200000000000001 2.319999999999998下面的是soap2.7头:13.18 24.3599999999999999差异是相反的。我如何更改我的wsdl,使soap主体从更改为?非常感谢..你救了我一天…在我更改gSoap-2.7.16之后,它工作正常。再次感谢,太好了。谢谢蒂米尔。使用您的XmlSerializerFormat(…),我回到了gSOAP版本2.8.12_2,没有问题,RPC对我有好处。