Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

c++ - Generate working Onvif code with wsdl2cpp

I generated the DeviceMgmt stub from cmd with

WSDL2CPP.bat -uri http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl -u -d adb -o OutputDirectory

The first time, I got an error like "No service was found" and I solved it by adding this:

<wsdl:service name="OnvifService">
  <wsdl:port name="OnvifEndpoint" binding="DeviceBinding">
    <soap:address location="http://www.onvif.org/ver10/device/wsdl"/>
  </wsdl:port>
</wsdl:service>

in devicemgmt.wsdl

I opened the generated project in VS2012 and set the project configuration type to dynamic library. After I compiled it I got a lot of errors like:

Error   907 error C2065: 'element' : undeclared identifier  d:projectsonvifdevicemgmtservicesrcunsupportedpolicyrequestfaulttype.cpp   878
Error   1725    error C2143: syntax error : missing ';' before '*'  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    46
Error   1726    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    46
Error   1731    error C2061: syntax error : identifier 'axutil_duration_t'  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    206
Error   2872    error C2143: syntax error : missing ';' before '*'  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    46
Error   2873    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    46  error C2660: 'axutil_base64_binary_set_encoded_binary' : function does not take 1 arguments d:projectsonvifdevicemgmtservicesrcmotionincells.cpp   343
Error   4114    error C2059: syntax error : ')' d:projectsonvifdevicemgmtservicesrcmotionincells.cpp   344
Error   4256    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  81
Error   4257    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  83
Error   4258    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  85
Error   4259    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  86
Error   4260    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  100
Error   4261    error C2065: 'cp' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  108
Error   4262    error C2664: 'axutil_qname_free' : cannot convert parameter 1 from 'void *' to 'axutil_qname *' d:projectsonvifdevicemgmtservicesrcmessagetypes_type0.cpp  416
Error   4695    error C2065: 'element' : undeclared identifier  d:projectsonvifdevicemgmtservicesrcinvalidfilterfaulttype.cpp  878
Error   6379    error C2065: 'env' : undeclared identifier  d:projectsonvifdevicemgmtservicesrcattributedqnametype.cpp 88
Error   6380    error C2227: left of '->allocator' must point to class/struct/union/generic type    d:projectsonvifdevicemgmtservicesrcattributedqnametype.cpp 88
Error   6381    error C2227: left of '->malloc_fn' must point to class/struct/union/generic type    d:projectsonvifdevicemgmtservicesrcattributedqnametype.cpp 88
Error   6382    error C2065: 'prefix' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcattributedqnametype.cpp 89
Error   6383    error C2065: 'prefix' : undeclared identifier   d:projectsonvifdevicemgmtservicesrcattributedqnametype.cpp 90
Error   6518    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    46
Error   6523    error C2061: syntax error : identifier 'axutil_duration_t'  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.h    206
Error   6524    error C3861: 'axutil_duration_create_from_string': identifier not found d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  132
Error   6525    error C2039: '_duration' : is not a member of 'org_xmlsoap_schemas_soap_envelope::AbsoluteOrRelativeTimeType::<unnamed-type-memberType>'    d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  229
Error   6526    error C3861: 'axutil_duration_serialize_duration': identifier not found d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  229
Error   6527    error C2143: syntax error : missing ';' before '*'  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  437
Error   6528    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  437
Error   6529    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  439
Error   6530    error C2039: '_duration' : is not a member of 'org_xmlsoap_schemas_soap_envelope::AbsoluteOrRelativeTimeType::<unnamed-type-memberType>'    d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  442
Error   6531    error C2059: syntax error : ')' d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  444
Error   6532    error C2065: 'member_type' : undeclared identifier  d:projectsonvifdevicemgmtservicesrcabsoluteorrelativetimetype.cpp  448
Error   6539    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_registry.h  65
Error   6540    error C2061: syntax error : identifier 'neethi_operator_t'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_assertion.h 179
Error   6541    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    58
Error   6542    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    58
Error   6543    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    58
Error   6544    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    62
Error   6545    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    79
Error   6546    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    79
Error   6547    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    79
Error   6548    error C2061: syntax error : identifier 'neethi_policy_t'    d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    83
Error   6549    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    83
Error   6550    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    103
Error   6551    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    103
Error   6552    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    103
Error   6553    error C2061: syntax error : identifier 'neethi_policy_t'    d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    106
Error   6554    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    108
Error   6555    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    122
Error   6556    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    122
Error   6557    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    122
Error   6558    error C2061: syntax error : identifier 'neethi_policy_t'    d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    125
Error   6559    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    126
Error   6560    error C2065: 'policy' : undeclared identifier   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    136
Error   6561    error C2059: syntax error : 'const' d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_engine.h    137
Error   6562    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  38
Error   6563    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  38
Error   6564    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  38
Error   6565    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  41
Error   6566    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  43
Error   6567    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  43
Error   6568    error C2086: 'int neethi_policy_t' : redefinition   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  43
Error   6569    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethi_util.h  46
Error   6570    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethipolicy.h 53
Error   6571    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethipolicy.h 53
Error   6572    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethipolicy.h 60
Error   6573    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethipolicy.h 60
Error   6575    error C2061: syntax error : identifier 'neethi_policy_t'    d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf-cpp-bin-2.1.0-win32include
eethipolicy.h 66
Error   6576    error C2143: syntax error : missing ';' before '*'  d:wsowso2-wsf-cpp-bin-2.1.0-win32wso2-wsf

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have not tried using WSO2, but have used svcutil.exe.

I added my client proxy using Visual Studio 2012,

  1. Add new Project, new ClassLibrary
  2. in solution explorer use the add new service reference context menu
  3. In the address, use url to the wsdl http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl
  4. Clik Go
  5. Select an apropiate name, like OnvifDeviceService.
  6. Clik Ok

This will auto generate the proxy for you. Mind that Onvif is using Soap12, so basicHttpBinding is out the window as this uses Soap1.1.

Use a WsHttpBinding or a custom binding to connect to your device.

Use the built in method for scanning for devices. Add a reference to System.ServiceModel.Discovery assembly, and this code will scan your network for devices. Some filtering for onvif devices must be implemented.

private FindResponse ScanNetwork(string scopeMathcBy, int iTimeoutMilliseconds)
    {
        ServicePointManager.Expect100Continue = false;

        UdpDiscoveryEndpoint oUdpDiscoveryEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
        DiscoveryClient oDiscoveryClient = new DiscoveryClient(oUdpDiscoveryEndpoint);

        // Create FindCriteria 
        var findCriteria = new FindCriteria
        {
            Duration = TimeSpan.FromMilliseconds(iTimeoutMilliseconds)
        };
        if (scopeMathcBy != null)
        {
            findCriteria.ScopeMatchBy = new Uri(scopeMathcBy);
        }

        var findResponse = oDiscoveryClient.Find(findCriteria);
        return findResponse;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...