gsoap2.8客户端和wcf服务()

时间:2012-12-20 21:20:00

标签: wcf gsoap

我遇到了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>

2 个答案:

答案 0 :(得分:1)

当WCF服务总是在请求Add(int n1,int n2)时返回0时,我遇到同样的问题。经过长时间的工作,我找到了解决方案,我的解决方法是应用gSoap 2.7.16而不是最后的2.8.1_2,它完美无缺。

答案 1 :(得分:1)

下班后,我修复了这个问题,如果你使用的是WCF,你需要在你的操作中添加一个属性,例如:

[ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        [XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Literal)]
        long Method1(int a, int b, long c, string d);
     }

所以gsoap可以正确地将参数值发送给服务器。