GSoap客户端无法将参数值传递给服务器

时间:2012-12-25 07:40:32

标签: c web-services gsoap

第1步,我使用ASP.NET(C#)创建了一个WebService:

[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

步骤3,在VC中创建一个空的C项目,添加以下文件:     soapH.h     soapStub.h     stdsoap2.h     soapC.c     soapClient.c     stdsoap2.c

步骤4,配置文件夹,并创建一个新类:

#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();
}

问题:返回值为&#34; 0,0&#34;,正如我们所期望的那样,它应该是&#34; 2,3&#34;, 请告诉我我对这些事情的遗漏?谢谢!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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

如果使用WebService,那应该是:

[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可以正确地将参数值发送给服务器。

相关问题