step 1, i had create an WebService using ASP.NET (C#):
[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();
}
}
step 2, and then i use gsoap_2.8.12 generate code, following command:
wsdl2h -c -o a.h http://localhost:29556/WebService1.asmx?WSDL
soapcpp2 -c -C -I import a.h
step3, create an empty C project in VC, add the following files: soapH.h soapStub.h stdsoap2.h soapC.c soapClient.c stdsoap2.c
step4, config the folders, and create a new class :
#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();
}
Problem: the return value is "0,0", as we expect it should be "2,3", Please tell me what i had missed about these things ? thanks!
after hours work, i had fixed this thing, if you are using WCF , you need add an attribute into your operation, for example:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Literal)]
long Method1(int a, int b, long c, string d);
}
if using WebService, that should be:
[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();
}
so the gsoap can send the argument value correctly to server.