How can I get my Spring.net Webservice working? - c#

I am trying to setup a Spring.net web-service but keep getting an error message that I cannot figure out.
Error:
System.NotSupportedException: Target 'target' of type 'Spring.Objects.Factory.Support.RootWebObjectDefinition' does not support methods of 'StudentRegistration.Services.IBoundaryService'.
at Spring.Util.AssertUtils.Understands(Object target, String targetName, Type requiredType)
at HelloWorldExporter.GetAllBounds()
Code:
public interface IBoundaryService {
XmlDocument GetAllBounds();
}
public class BoundaryService :IBoundaryService
{
public virtual IBoundaryDao BoundaryDao { get; set; }
public virtual XmlDocument GetAllBounds()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<test>ok</test>");
return xmlDoc;
}
}
Configuration:
<object name="BoundaryService" type="StudentRegistration.Services.BoundaryService, StudentRegistration"
abstract="true">
</object>
<object id="BoundaryExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="BoundaryService"/>
<property name="Namespace" value="http://fake/services"/>
<property name="Description" value="something"/>
<property name="MemberAttributes">
<dictionary>
<entry key="GetAllBounds">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="something."/>
<property name="MessageName" value="GetAllBounds"/>
</object>
</entry>
</dictionary>
</property>
</object>
What should I try to clear this up?

The Spring.NET reference is wrong on the xml declaration (i had the same issue a few days ago), or should i say its not crystal clear.
<object name="BoundaryService"
type="StudentRegistration.Services.BoundaryService, StudentRegistration"
abstract="true" />
the above declaration applies when you have an actual .asmx service
WHen you have a PONO which you export as a WebService using Spring.Web.Services.WebServiceExporter the object that will be exported must be declared as:
<object id="BoundaryService"
type="StudentRegistration.Services.BoundaryService, StudentRegistration"
/>
the target property of the WebServiceExporter applies to the id of a declared object, the abstract part is not required as Spring.NET takes the role generating the webservice.
Note that your exposed service name (with your current cfg) will be (..)/BoundaryExporter.asmx
Edit:
The config statement for standard .asmx web services using the name, type attributes seems to be broken, at least for spring version 1.3.0.20349

Related

How Can i associate an aspect and his property to a document in C# DotCmis Alfresco

I am working in a .net web application than need to be able to create documents in Alfresco and then associate a particular aspect and his prperties to those documents.
I created my aspect (nameModel.xml, name-model-context.xml all this files in the extension folder, name.properties in messages folder and custom-slingshot-application-context.xml share-config-custom.xml in the web-extension folder) in /opt/bitnami/apache-tomcat/shared/classes/alfresco/ path.
In my C# code, i have two methods:
public void PutFile(CMISDocument document)
{
IObjectId cmisObjectFolder = (IObjectId)session.GetObject(document.FolderId);
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = document.ContentStreamFileName;
properties[PropertyIds.ObjectTypeId] = "cmis:document";
properties[PropertyIds.CreationDate] = DateTime.Now;
ContentStream contentStream = new ContentStream();
contentStream.FileName = document.ContentStreamFileName;
contentStream.MimeType = document.ContentStreamMimeType;
contentStream.Length = document.Stream.Length;
contentStream.Stream = document.Stream;
IObjectId objectId = session.CreateDocument(properties, cmisObjectFolder, contentStream, DotCMIS.Enums.VersioningState.None);
PutFileDetail(objectId,document.Owner);
}
internal void PutFileDetail(IObjectId objectId,string actorIdCard)
{
ICmisObject cmisObject = session.GetObject(objectId);
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.ObjectTypeId] = "adm:aridoctypBase";
properties["adm:actidcard"] = actorIdCard;
IObjectId newId = cmisObject.UpdateProperties(properties);
if (newId.Id == cmisObject.Id)
{
// the repository updated this object - refresh the object
cmisObject.Refresh();
}
else
{
// the repository created a new version - fetch the new version
cmisObject = session.GetObject(newId);
}
}
With this code i have as result a error:
The first one is for create the document and the second one is for add the aspect and his properties.
I was looking for a answer, and i finded this: http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-intro.html
But a really do not know how install Alfresco OpenCMIS Extension; they say that i need put the jar file in my class path. But i do not know what is my class path in bitnami virtual machine.
Other thing is if i forgot something in the creation of my aspect.
pd: It is important but nor urgent for me, that the way to do it could be work if one day a need change Alfresco to Sharepoint or another else enterprise content management
I will apreciate any help.
Thanks! Do you know where can i see a good example? I think that the first point: i need change my model. In this moment i have the properties inside of aspect tags. I will need create the types and the properties ... can you tell me if i am going in good way...?
This is my model xml file (aridocsModel.xml) resume:
<?xml version="1.0" encoding="UTF-8"?>
<model name="adm:aridocsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
...
<aspects>
<aspect name="adm:aridocsBase">
<title>AriDocs Base</title>
<properties>
<property name="adm:createdate">
<type>d:date</type>
</property>
<property name="adm:disabledate">
<type>d:date</type>
</property>
<property name="adm:artiddoc">
<type>d:text</type>
</property>
<property name="adm:accnumber">
<type>d:text</type>
</property>
<property name="adm:actidcard">
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
Now, how i can not work with aspects; and i need types ...
<?xml version="1.0" encoding="UTF-8"?>
<model name="adm:aridocsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
...
<types>
<type name="adm:aridoctypBase">
<title>Ari Docs Type Base</title>
<parent>cm:content</parent>
<properties>
<property name="adm:createdate">
<type>d:date</type>
</property>
<property name="adm:disabledate">
<type>d:date</type>
</property>
<property name="adm:artiddoc">
<type>d:text</type>
</property>
<property name="adm:accnumber">
<type>d:text</type>
</property>
<property name="adm:actidcard">
<type>d:text</type>
</property>
</properties>
</type>
</types>
...
<!-- i need put the aspect here... Even if i will work with types... -->
...
</model>
I will appreciate any advice.
You don't need the extensions on creating a document. The extension is only for managing aspects.
And from what I've heard the extension isn't available in all the languages, so I'm not sure if there is a .dll for you to include in your project.
Did you read these topics: integrate a .net application with alfresco using cmis
And: .net wcf and create document

How do I create a spring .Net standalone object of type Int32 defined in the IOC context file?

Kind of a simple newbie question...I see how I can create a string object, but how would I create an int object?
Here is the xml code fragment from my context file:
<object id="myString" type="System.String">
<constructor-arg value="foo" />
</object>
<object id="myInt" type="System.Int32">
<<<**** how do I set this ****>>>>
</object>
Try this:
<object id="MyInt" type="System.Int32" factory-method="Copy">
<constructor-arg index="0">
<value>123</value>
</constructor-arg>
</object>
Try this:
<object id="MyInt" type="System.Int32" factory-method="Parse">
<constructor-arg index="0">
<value>123</value>
</constructor-arg>
</object>
For creating an object of primitive type System.Int32, you must use the factory-method="Parse". The attribute factory-method="Copy" doesn't works because it not exists in the type System.Int32 and you have to use a static method to do it.

SpringNet load configuration file from environment variable?

I use C# and Spring Net 1.3.2 in console app.
I got :
an app.cfg
a spring-context.xml
a environnement.xml file wich contains specific variables values according to the where the app is running : a folder for production, one for qa, and one for test.
What I want to achieve :
in my shell (windows), before launching the app with foo.bat, I do :
set environment="qa"
When Spring loads the context, it picks the value contained in the environment var (say qa), and loads the correct file : thus replacing : configuration/{environment}/vars.xml
by configuration/qa/vars.xml.
In my my spring-context.xml file, I got objects like this : value = ${connectionString.DB1}" where the value is defined inside each vars.xml file (remember, one for prod, one for qa...).
For now, I am not able to replace the ${environment} variable. So I did it programmatically by getting the value of ${environment} with System.Environment.GetEnvironmentVariable("environnement"); and using Path.Combine, load the two contexts myself :
reader.LoadObjectDefinitions(envPath);
reader.LoadObjectDefinitions("configuration/common/springContext.xml");
BUT :
I would like to make it by configuration.
I've been playing with (with no luck) :
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
</list>
</property>
</object>
<object name="appConfigPropertyHolder"
type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="EnvironmentVariableMode" value="Override"/>
</object>
Any ideas ?
Ok, after much research, it works!
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
<object type="Spring.Objects.Factory.Config.PropertyFileVariableSource, Spring.Core">
<property name="Location" value="${root.config}/envars.properties" />
<property name="IgnoreMissingResources" value="false"/>
</object>
</list>
</property>
</object>
path to property file depends upon the environment variable.
Variables are replaced by the values obtained from the properties file.
I deploy one package + folder with 4 environment properties files
And I set my env var accordingly.
No need to mess with app.config or multiple Spring configuration files.

Unit tests failing only on the build server

It throws an exception that is something like this:
Initialization method MyAssemblyA.Initialize threw exception.
Spring.Objects.Factory.ObjectCreationException: Spring.Objects.Factory.ObjectCreationException:
Error thrown by a dependency of object 'messageSource' defined in 'assembly
[MyOtherAssembly.Test, Version=1.1.1016.1, Culture=neutral, PublicKeyToken=null],
resource [MyOtherAssembly.context.xml]
line 256' : Initialization of object failed : Could not load file or assembly 'MyAssemblyB'
or one of its dependencies. The system cannot find the file specified.
I don't know exactly why, but a lot of the unit tests are failing only on the build server and the exception that is thrown is something similar to what I wrote above.
In my context.xml I have something like this:
<object name="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="resourceManagers">
<list>
<ref object="resMgrCoreServiceErrors"/>
<ref object="resMgrPersonnelErrors"/>
</list>
</property>
</object>
<object name="resMgrCoreServiceErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssembly.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssembly"/>
</object>
<object name="resMgrPersonnelErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssemblyB.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssemblyB"/>
</object>
where ErrorRes is a resource file (.resx).
Please help, any suggestions are welcomed !
are all of the dependencies of MyAssemblyB either installed in the gac or in the bin? has to be something in that vein.

How to specify an object property type in Spring.NET

I am trying to create an object in Spring where one of its propertys is of type object. Now if I do the following:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4">
</object>
Then the property my_property will be a string object. Is there a way do something like:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4" type="System.Double, System">
</object>
I know this should probably be done by generics but we can't really add this in now as the person who wrote it didn't think of this at the time.
You should be able to do this using the 'expression' tag. e.g.
<property name="my_property" expression="double.Parse('4')" />
See the Spring.NET documentation here

Categories

Resources