WCF 和 gSOAP - 可互操作的代码?

发布于 2024-07-16 06:43:07 字数 1856 浏览 5 评论 0原文

我正在尝试使用 SOAP 1.2 协议编写一个简单的 WCF 服务器 + gSOAP 客户端概念验证应用程序。 这是服务器代码:

[ServiceContract(Namespace="http://test.com")]
public interface IService1
{
    [OperationContract]
    void HelloWorld();
}

[ServiceBehavior(Namespace = "http://test.com")]
public class Service1 : IService1
{
    public void HelloWorld()
    {
    }
}

static void Main(string[] args)
{
    var svc =  new Service1();
    Uri uri = new Uri("http://localhost:8201/Service1");
    ServiceHost host = new ServiceHost(typeof(Service1), uri);
    host.Description.Namespace = "http://test.com";

    var binding = new WSHttpBinding() { Namespace = "http://test.com" };
    ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
    endpoint.Behaviors.Add(new InlineXsdInWsdlBehavior());

    host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
    var mex = host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
    host.Open();

    Console.ReadLine();
}

然后我启动服务并使用以下命令生成代码:

wsdl2h.exe -gyf -t WS/WS-typemap.dat -o Service.h http://localhost:8201/Service1?wsdl WS/WS-Addressing05.xsd
soapcpp2.exe -C -L -w -x -i -2 Service.h -ID:\...\gsoap-2.7\gsoap\import

然后我编译以下 C++ 代码:

#include "soapWSHttpBinding_USCOREIService1Proxy.h"
#include "WSHttpBinding_USCOREIService1.nsmap"
#include "stdsoap2.h" 

int _tmain(int argc, _TCHAR* argv[])
{
    WSHttpBinding_USCOREIService1Proxy svc;

    _ns1__HelloWorld req;
    _ns1__HelloWorldResponse rsp;
    int hr = svc.HelloWorld( &req, &rsp );
    if ( hr != SOAP_OK )
    {
        _tprintf( _T("Error: %i\n"), hr );
    }

    return 0;
}

这会生成错误 8 (SOAP_MUSTUNDERSTAND)。 有人曾经生成过有效的 WCF 到 gSOAP 链接吗? 我究竟做错了什么?

I'm trying to write a simple WCF Server + gSOAP client proof-of-concept application using SOAP 1.2 protocol. Here's server code:

[ServiceContract(Namespace="http://test.com")]
public interface IService1
{
    [OperationContract]
    void HelloWorld();
}

[ServiceBehavior(Namespace = "http://test.com")]
public class Service1 : IService1
{
    public void HelloWorld()
    {
    }
}

static void Main(string[] args)
{
    var svc =  new Service1();
    Uri uri = new Uri("http://localhost:8201/Service1");
    ServiceHost host = new ServiceHost(typeof(Service1), uri);
    host.Description.Namespace = "http://test.com";

    var binding = new WSHttpBinding() { Namespace = "http://test.com" };
    ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
    endpoint.Behaviors.Add(new InlineXsdInWsdlBehavior());

    host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
    var mex = host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
    host.Open();

    Console.ReadLine();
}

Then I launch service and generate code using following commands:

wsdl2h.exe -gyf -t WS/WS-typemap.dat -o Service.h http://localhost:8201/Service1?wsdl WS/WS-Addressing05.xsd
soapcpp2.exe -C -L -w -x -i -2 Service.h -ID:\...\gsoap-2.7\gsoap\import

Then I compile following C++ code:

#include "soapWSHttpBinding_USCOREIService1Proxy.h"
#include "WSHttpBinding_USCOREIService1.nsmap"
#include "stdsoap2.h" 

int _tmain(int argc, _TCHAR* argv[])
{
    WSHttpBinding_USCOREIService1Proxy svc;

    _ns1__HelloWorld req;
    _ns1__HelloWorldResponse rsp;
    int hr = svc.HelloWorld( &req, &rsp );
    if ( hr != SOAP_OK )
    {
        _tprintf( _T("Error: %i\n"), hr );
    }

    return 0;
}

and this generates error 8 (SOAP_MUSTUNDERSTAND). Have anyone ever generated working WCF to gSOAP link at all? What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-07-23 06:43:07

我猜soapcpp2中的-a开关已经修复了错误8,所以开关现在是:

soapcpp2.exe -C -L -w -x -i -2 -a Service.h -I<...path...>

I guess -a switch in soapcpp2 have fixed error 8, so the switches are now:

soapcpp2.exe -C -L -w -x -i -2 -a Service.h -I<...path...>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文