2012-12-25 32 views
0

步骤1中,我不得不创建使用ASP.NET(C#)的web服务:gSOAP的客户机不能传递参数值到服务器

[WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    public class WebService1 : System.Web.Services.WebService 
    { 

     [WebMethod] 
     public string HelloWorld(int a, int b) 
     { 
      return a.ToString() + "," + b.ToString(); 
     } 
    } 

步骤2,然后我使用gsoap_2.8.12生成代码,下面的命令:

wsdl2h -c -o a.h http://localhost:29556/WebService1.asmx?WSDL 
    soapcpp2 -c -C -I import a.h 

第三步,创建一个VC为空,C项目中添加下列文件: soapH.h soapStub.h stdsoap2.h soapC.c soapClient.c stdsoap2.c

第四步,配置的文件夹,并创建一个新的类:

#include <stdio.h> 
#include "WebService1Soap.nsmap"; 

void main() 
{ 
    struct soap soap; 
    int ret; 
    struct _ns1__HelloWorld hello; 
    struct _ns1__HelloWorldResponse respHello; 
    int arg1, arg2; 

    soap_init(&soap); 
    hello.a = 2; 
    hello.b = 3; 

    ret = soap_call___ns1__HelloWorld(&soap, NULL, NULL, &hello, &respHello); 
    if (ret == SOAP_OK) 
    { 
     printf("return :%s", respHello.HelloWorldResult); 
    } 
    else 
    { 
     printf("error :%d", ret); 
    } 

    getchar(); 
} 

问题:返回值是“0,0”,因为我们预计它应该是“2,3” , 请告诉我我错过了这些东西?谢谢!

回答

0

后的工作时间,我已经修正了这个东西,如果你正在使用WCF,您需要添加属性到你的操作,例如:

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

,这应该是:

[WebMethod] 
     [System.Web.Services.Protocols.SoapRpcMethodAttribute(Use = System.Web.Services.Description.SoapBindingUse.Literal)] 
     public string HelloWorld(int a, int b) 
     { 
      return a.ToString() + "," + b.ToString(); 
     } 

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

0

我有类似的问题,当服务接收参数为0,因此它返回0.希望这可以帮助你。 gsoap2.8 client and wcf service()

+0

太好了。谢谢你timiil。使用你的XmlSerializerFormat(...)我回到gSOAP 2.8.12_2版本没有问题,RPC对我有好处 – dzzunga

相关问题