Unity 3: The type does not have an accessible constructor - inversion-of-control

I have a following interface and implementation
namespace ProjectName.Web
{
public interface IWebUtil
{
}
}
namespace ProjectName.Web
{
public class WebUtil : IWebUtil
{
}
}
in my config i have this registration. I am using Unity 3.
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="ProjectName.Web" />
...
<register name="WebUtil" type="ProjectName.Web.IWebUtil" mapTo="ProjectName.Web.WebUtil">
<lifetime type="transient" />
</register>
...
When I try to resolve this configuration I am getting this error:
Exception is: InvalidOperationException - The type IWebUtil does not have an accessible constructor.
-----------------------------------------------
At the time of the exception, the container was:
Resolving ProjectName.Web.IWebUtil,(none)
I have tried to add empty public constructor but no sucess.
Can anybody help with this? thanks.

The first step is to ensure that you are loading the Unity configuration since this is not done by default. To do this:
using Microsoft.Practices.Unity.Configuration;
container.LoadConfiguration();
I'm assuming you've done this. I'm also going to assume that you are trying to resolve IWebUtil using the following code:
container.Resolve<IWebUtil>();
This throws an InvalidOperationException because IWebUtil is configured as a named registration (with name "WebUtil"). So either resolve using the configured name:
container.Resolve<IWebUtil>("WebUtil");
Or change the registration to be a default (unnamed) registration:
<register name="" type="ProjectName.Web.IWebUtil" mapTo="ProjectName.Web.WebUtil">
<lifetime type="transient" />
</register>

Related

Sulu: error when trying to use custom data provider

I'm following docs from here: https://docs.sulu.io/en/2.2/cookbook/smart-content-data-provider.html
Trying to make custom data provider for my custom entity type "MatchEvent":
I did it how it's explained here. Since I have services.yaml file I defined those 2 like this:
app.match_event_repository:
class: App\Repository\MatchEventRepository
factory: ['#doctrine', 'getRepository']
arguments:
- Symfony\Bridge\Doctrine\ManagerRegistry
app.smart_content.data_provider.matchevent:
class: App\SmartContent\MatchEventDataProvider
arguments: ['#app.match_event_repository', '#sulu_core.array_serializer', '#request_stack' ]
tags: [{name: 'sulu.content.type', alias: 'smart_matchevent_selection'}]
So, if I understood well, after that I should have my custom content data provider named "smart_matchevent_selection" and I can use it like this:
<property name="match" type="smart_content">
<meta>
<title lang="en">Match</title>
<title lang="de">Match</title>
</meta>
<params>
<param name="provider" value="smart_matchevent_selection"/>
</params>
</property>
But when I try to edit page containing this field I get error:
Missing parameter token in Sulu\Bundle\PreviewBundle\Controller\PreviewController
Exception is triggered at project/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Controller/PreviewController.php:
public function stopAction(Request $request): Response
{
$this->preview->stop($this->getRequestParameter($request, 'token', true));
return new JsonResponse();
}
What I'm doing wrong here?
If you carefully look at the service definition of the SmartContentDataProvider in the documentation, you will notice that the tag should be {name: 'sulu.smart_content.data_provider', alias: 'match_events'} instead of {name: 'sulu.content.type', alias: 'smart_matchevent_selection'} ...
Then you can use it like <param name="provider" value="match_events"/>

Mono WCF Rest Service With Multiple Contracts "no endpoints are defined in the configuration file"

I want to host a WCF Rest Service with multiple contracts via mono each implemented in a separate partial class. I read many posts on similar issues, yet there was no solution for mono. I incorporated or at least tested all suggestions I could find and by now my code looks a lot like other solutions, yet does not work.
The application runs successfully on my local machine but throws an error once I deploy it via mono.
Service 'MyWebServiceEndpoint' implements multiple ServiceContract types, and no endpoints are defined in the configuration file.
Here is one of the endpoints with the contract. All the others are very much like this one. They all are a partial class MyWebServiceEndpoint implementing another contract.
namespace MyServer.MyEndPoints {
public partial class MyWebServiceEndpoint : INotificationEndpoint {
public string GetNotifications(int limit) {
// Do stuff
}
}
[ServiceContract]
public interface INotificationEndpoint {
[OperationContract]
[WebGet]
string GetNotifications(int limit);
}
}
My App.config looks like this. I removed the IP and port, as they are the server address.
<system.serviceModel>
<services>
<service name="MyServer.MyEndPoints.MyWebServiceEndpoint" behaviorConfiguration="WebService.EndPoint">
<host>
<baseAddresses>
<add baseAddress="http://ip:port>"/>
</baseAddresses>
</host>
<endpoint address="/message"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.IMessageEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="/music"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.IMusicEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="/notification"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.INotificationEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WebService.EndPoint">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
I open the service in C# like this.
WebServiceHost = new WebServiceHost(typeof(MyWebServiceEndpoint));
WebServiceHost.Open();
The Error message I receive on mono is:
Unhandled Exception:
System.InvalidOperationException: Service 'MyWebServiceEndpoint' implements multiple ServiceContract
types, and no endpoints are defined in the configuration file. WebServiceHost can set up default
endpoints, but only if the service implements only a single ServiceContract. Either change the
service to only implement a single ServiceContract, or else define endpoints for the service
explicitly in the configuration file. When more than one contract is implemented, must add base
address endpoint manually
I hope you have some hints or someone knows how to solve the issue. Thank you already for reading up to here.
I am not familiar with Mono, Does the Mono support Webconfig file? I advise you to add the service endpoint programmatically.
class Program
{
/// <param name="args"></param>
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
Uri uri = new Uri("http://localhost:21011");
using (WebServiceHost sh = new WebServiceHost(typeof(TestService),uri))
{
sh.AddServiceEndpoint(typeof(ITestService), binding, "service1");
sh.AddServiceEndpoint(typeof(IService), binding, "service2");
ServiceMetadataBehavior smb;
smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
smb = new ServiceMetadataBehavior()
{
HttpGetEnabled = true
};
sh.Description.Behaviors.Add(smb);
}
sh.Opened += delegate
{
Console.WriteLine("service is ready");
};
sh.Closed += delegate
{
Console.WriteLine("service is closed");
};
sh.Open();
Console.ReadLine();
sh.Close();
}
}
}
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebGet]
string GetData(int id);
}
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string Test();
}
public class TestService : ITestService,IService
{
public string GetData(int id)
{
return $"{id},";
}
public string Test()
{
return "Hello " + DateTime.Now.ToString();
}
}
Result.
According to the official documentation, we had better not use Partial class.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/multiple-contracts
Besides, we could consider launching multiple service host for every service implemented class.
Feel free to let me know if the problem still exists.

ejb 2 FinderException table or view does not exist

I'm working with an existing database and EJB 2.x application.
My task is to migrate the app from WebSphere 8 over to JBOSS EAP 6.4
After many days of fighting with this thing, everything seemed to be working until we started trying to use some of the beans. There are beans that end with "Mgr". For example, there is a SiteMgr bean and a Site bean. Right now, all of the Mgr beans work, but not the rest.
If you couldn't tell already, I'm not an EJB 2 Guru. Here is code that errors out:
/**
* getSessionContext
*/
public SiteVO getSite(int siteId) {
SiteLocal siteLocal;
try {
siteLocal = getSiteHome().findByPrimaryKey(new SiteKey(siteId));
} catch (FinderException e) {
throw new EJBException(e);
}
return siteLocal.getSiteVO();
}
So, when I try to findByPrimaryKey I get javax.ejb.FinderException, with the following cause:
java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
Drilling into that a bit more, here is the cause:
Error : 942, Position : 27, Sql = SELECT t0_Site.siteId FROM SITE t0_Site WHERE t0_Site.siteId=:1 , OriginalSql = SELECT t0_Site.siteId FROM SITE t0_Site WHERE t0_Site.siteId=?, Error Msg = ORA-00942: table or view does not exist
The database contains a table named APP_SITES and the WebSphere app probably figures that out using some files that appear to be specific to WebSphere.
There is appdb70.dbm and Map.mapxmi
These files are very long. I will provide some example text that is specific to the above example.
ejb-jar.xml
<entity id="Site">
<ejb-name>Site</ejb-name>
<local-home>com.app.site.entity.SiteLocalHome</local-home>
<local>com.app.site.entity.SiteLocal</local>
<ejb-class>com.app.site.entity.SiteBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.app.site.entity.SiteKey</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Site</abstract-schema-name>
<cmp-field id="CMPAttribute_1087249279390">
<field-name>siteId</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1087249281781">
<field-name>siteName</field-name>
</cmp-field>
...
Map.mapxmi
<ejbrdbmapping:EjbRdbDocumentRoot xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:OracleModel="http:///com/ibm/db/models/oracle/oracle.ecore"
xmlns:SQLConstraints="http:///org/eclipse/datatools/modelbase/sql/constraints.ecore"
xmlns:SQLTables="http:///org/eclipse/datatools/modelbase/sql/tables.ecore" xmlns:ejb="ejb.xmi"
xmlns:ejbrdbmapping="ejbrdbmapping.xmi" xmlns:Mapping="Mapping.xmi" xmi:id="EjbRdbDocumentRoot_1289312938455" topToBottom="true" commandStack="">
<helper xmi:type="ejbrdbmapping:RdbSchemaProperies" xmi:id="RdbSchemaProperies_1289312938455" primitivesDocument="ORACLE_V11"/>
<nested xmi:type="ejbrdbmapping:RDBEjbMapper" xmi:id="RDBEjbMapper_1289313262395">
<helper xmi:type="ejbrdbmapping:PrimaryTableStrategy" xmi:id="PrimaryTableStrategy_1289313262395">
<table xmi:type="OracleModel:OracleTable" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x58OwNEd-LtOpsZa3J5w"/>
</helper>
<nested xmi:type="ejbrdbmapping:RDBEjbFieldMapper" xmi:id="RDBEjbFieldMapper_1289315290408">
<inputs xmi:type="ejb:CMPAttribute" href="META-INF/ejb-jar.xml#CMPAttribute_1087249279390"/>
<outputs xmi:type="SQLTables:Column" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x58ewNEd-LtOpsZa3J5w"/>
<typeMapping xmi:type="ejbrdbmapping:RDBEjbFieldMapper" href="JavatoORACLE_V11TypeMaps.V7.xmi#int-NUMBER"/>
</nested>
<nested xmi:type="ejbrdbmapping:RDBEjbFieldMapper" xmi:id="RDBEjbFieldMapper_1289315290409">
<inputs xmi:type="ejb:CMPAttribute" href="META-INF/ejb-jar.xml#CMPAttribute_1087249285656"/>
<outputs xmi:type="SQLTables:Column" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x5-ewNEd-LtOpsZa3J5w"/>
<typeMapping xmi:type="ejbrdbmapping:RDBEjbFieldMapper" href="JavatoORACLE_V11TypeMaps.V7.xmi#String-VARCHAR"/>
</nested>
appdb70.dbm (contains WAY too much data to post...)
<?xml version="1.0" encoding="UTF-8"?>
<!--xtools2_universal_type_manager-->
<xmi:XMI xmlns:datamodelversion="http://www.ibm.com/com.ibm.datatools.core/model/7.5.1.1" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:OracleModel="http:///com/ibm/db/models/oracle/oracle.ecore" xmlns:SQLConstraints="http:///org/eclipse/datatools/modelbase/sql/constraints.ecore" xmlns:SQLDataTypes="http:///org/eclipse/datatools/modelbase/sql/datatypes.ecore" xmlns:SQLExpressions="http:///org/eclipse/datatools/modelbase/sql/expressions.ecore" xmlns:SQLSchema="http:///org/eclipse/datatools/modelbase/sql/schema.ecore" xmlns:SQLStatements="http:///org/eclipse/datatools/modelbase/sql/statements.ecore" xmlns:SQLTables="http:///org/eclipse/datatools/modelbase/sql/tables.ecore">
<OracleModel:OracleDatabase xmi:id="_WPDywewNEd-LtOpsZa3J5w" name="APPdb70" vendor="Oracle" version="11" schemas="_WQG7oOwNEd-LtOpsZa3J5w"/>
<SQLSchema:Schema xmi:id="_WQG7oOwNEd-LtOpsZa3J5w" name="APPWDB" triggers="_q0VNoOwNEd-LtOpsZa3J5w ..." database="_WPDywewNEd-LtOpsZa3J5w"/>
<SQLTables:Trigger xmi:id="_q0VNoOwNEd-LtOpsZa3J5w" name="APP_APPOINTMENT_D_TRG" schema="_WQG7oOwNEd-LtOpsZa3J5w" subjectTable="_q0VNpuwNEd-LtOpsZa3J5w" ...>
<dependencies xmi:id="_q0VNoewNEd-LtOpsZa3J5w" targetEnd="_q07ry-wNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNouwNEd-LtOpsZa3J5w" targetEnd="_q0e_b-wNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNo-wNEd-LtOpsZa3J5w" targetEnd="_q0VNpuwNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNpOwNEd-LtOpsZa3J5w" targetEnd="_q0VN_OwNEd-LtOpsZa3J5w"/>
<actionStatement xsi:type="SQLStatements:SQLStatementDefault" ..."/>
</SQLTables:Trigger>
<OracleModel:OracleTable xmi:id="_q0VNpuwNEd-LtOpsZa3J5w" name="APP_APPOINTMENT" schema="_WQG7oOwNEd-LtOpsZa3J5w" triggers="_q0VNoOwNEd-LtOpsZa3J5w ...>
<columns xmi:id="_q0VNp-wNEd-LtOpsZa3J5w" name="APPT_ID" nullable="false">
<containedType xsi:type="SQLDataTypes:FixedPrecisionDataType" xmi:id="_q0VNqOwNEd-LtOpsZa3J5w" name="NUMBER" primitiveType="NUMERIC"/>
</columns>
<columns xmi:id="_q0VNqewNEd-LtOpsZa3J5w" name="RMKS_TX">
<containedType xsi:type="SQLDataTypes:CharacterStringDataType" xmi:id="_q0VNquwNEd-LtOpsZa3J5w" name="VARCHAR2" primitiveType="CHARACTER_VARYING" length="200"/>
</columns>
Notice that you can find "CMPAttribute_1087249279390" in multiple files. JBOSS does not seem to make use of these extra files.
I'm not sure what to do at this point. I figured out everything else, but I can't seem to get around this. Any fix that gets the beans to work would be appreciated!

Zend Framework 2 SOAP server WSDL failed to load

I can't get the SOAP server working in Zend Framework 2 module. I am not completely sure, but I believe that the problem is the WSDL file. I try to create the WSDL file via Autodiscover, which is provided by the Zend Framework. Here is the error.log:
[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Warning: SoapServer::SoapServer(): I/O warning : failed to load external entity "http-LINK/services?wsdl" in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"\n in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
I added an own module for this services test, this is the structure, module is called "Services":
-Services
--config
---module.config.php
--src
---Services
----API
-----1.0
------servicesAPI.php
---Controller
----ServicesController.php
--view
---services
----serivces
-Module.php
-autoload_classmap.php
This is my file "servicesAPI.php"
class servicesAPI {
/**
* This method takes a value and gives back the md5 hash of the value
*
* #param String $value
* #return String
*/
public function md5Value($value) {
return md5($value);
}
}
And this is ServicesController.php:
namespace Services\Controller;
ini_set("soap.wsdl_cache_enabled", 0);
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\AutoDiscover;
use Zend\Soap\Server;
require_once __DIR__ . '/../API/1.0/servicesAPI.php';
class ServicesController extends AbstractActionController {
private $_options;
private $_URI = "http-LINK/services";
private $_WSDL_URI = "http-LINK/services?wsdl";
public function indexAction() {
if (isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
private function handleWSDL() {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('servicesAPI')
->setUri($this->_URI);
$autodiscover->handle();
}
private function handleSOAP() {
$soap = new Server($this->_WSDL_URI);
$soap->setClass('servicesAPI');
$soap->handle();
}
}
So when I deploy this and open http-LINK/services in the browser, it gives me the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"
</faultstring>
<detail/>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
On this call also the PHP error output is written!
If I try to open the services?wsdl in browser, it shows me this (chrome and safari):
This page contains the following errors:
error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
This method takes a value and gives back the md5 hash of the value
But if I inspect the element, it looks completely ok:
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http-LINK/services" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="servicesAPI" targetNamespace="http-LINK/services"><types><xsd:schema targetNamespace="http-LINK/services"/></types><portType name="servicesAPIPort"><operation name="md5Value"><documentation>This method takes a value and gives back the md5 hash of the value</documentation><input message="tns:md5ValueIn"/><output message="tns:md5ValueOut"/></operation></portType><binding name="servicesAPIBinding" type="tns:servicesAPIPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="md5Value"><soap:operation soapAction="http-LINK/services#md5Value"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></output></operation></binding><service name="servicesAPIService"><port name="servicesAPIPort" binding="tns:servicesAPIBinding"><soap:address location="http-LINK/services"/></port></service><message name="md5ValueIn"><part name="value" type="xsd:string"/></message><message name="md5ValueOut"><part name="return" type="xsd:string"/></message></definitions>
I can validate this xml with any xml validator, it seems to be valid.
I read all the posts concerning this on stackoverflow, searched google, but none of the solutions helped me. Here a short list of what else I tried:
According to this: https://bugs.php.net/bug.php?id=48216 I tried to save the wsdl xml to a file and open it from this file when starting the soap server, fail
I tried to run the autodiscover and soapserver statements with try/catch to catch any exceptions, nothing appears
I tried with echo-ing through toXML() and other outputs, fail
Used XMLReader::open and isValid to make sure, that the xml is valid (it is)
Some more information:
PHP Version 5.3.23
Ubuntu server 11.04
php-soap module is loaded
Zend Framework version 2.1.4
Any help or hints are appreciated. Thanks in advance.
Try instantiate the Soap Server class this way:
...
private function handleSOAP() {
$soap = new Server(
null, array(,
'wsdl' => http-LINK/services?wsdl,
)
);
$soap->setClass('servicesAPI');
$soap->handle();
}
....
Also you should add this line to the end of your indexAction()
return $this->getResponse();
.. it disables the layout.

Symfony DIC and Parent Services not working

I'm integrating Symfony DIC in a zend framework application, that's going fine except for parent services.
In my DIC config I have a parent service PC_Service which will be extended by all my services.
The problem is that the entity manager is not available (NULL) in the services that extend PC_Service. When I inject the entitymanager via service.stats the entitymanger is set correctly.
...
<service id="pc.service" class="PC_Service" abstract="true">
<call method="setEntityManager">
<argument type="service" id="doctrine.entitymanager" />
</call>
</service>
...
<service id="service.stats" class="Application_Service_Stats" parent="pc.service" />
...
PC_Service
abstract class PC_Service
{
protected $_em;
public function setEntityManager($entityManager)
{
$this->_em = $entityManager;
}
}
Application_Service_Stats
class Application_Service_Stats extends PC_Service
{
... $this->_em should be set here.
}
I hope someone can tell me what I'm doing wrong.
Don't know if it's a typo but it should be doctrine.orm.default_entity_manager or doctrine.orm.entity_manager (alias of the previuos):
<service id="pc.service" class="PC_Service" abstract="true">
<call method="setEntityManager">
<argument type="service" id="doctrine.orm.default_entity_manager" />
</call>
</service>
The solution is to compile the service container near the end of the ZF bootstrap. This process has a step called ResolveDefinitionTemplatesPass which patches in the calls from parent services.
This is typically done by the Symfony Kernel, but of course it isn't present in a ZF integration.
protected function _initServiceContainerCompilation()
{
// Wait for the SC to get built
$this->bootstrap('Services');
// Doctrine modifies the SC, so we need to wait for it also
$this->bootstrap('Doctrine');
// Compiling the SC allows "ResolveDefinitionTemplatesPass" to run,
// allowing services to inherit method calls from parents
$sc = $this->getResource('Services');
$sc->compile();
}