I would need to set an attribute value in the WSDL for a JAX-WS WebService. I found that this can be done using the #XmlAttribute annotation for a "public static final" field of a complex type, but how do I actually pass the value from my class to the WSDL? For example, I have a class that is used as an argument for a method:
#XmlType(name = "argument")
public class Argument {
#XmlAttribute
public static final int fixer = 7;
}
This would create the following WSDL:
<xs:attribute name="fixer" type="xs:int" use="required"/>
But what I need is:
<xs:attribute name="fixer" type="xs:int" use="required" fixed=7/>
How to accomplish this using JAX-WS annotation?
Any help would be appreciated!
EDIT: added 'final' modifier
Related
This is the DTO C# class:
public class WeatherForecast
{
public string DateFormatted { get; set; }
}
This is what is generated in the swagger definition:
{"WeatherForecast":{"type":"object","properties":{"dateFormatted":{"type":"string"}}}}
The problem is that when I generate an XML example:
<?xml version="1.0" encoding="UTF-8"?>
<WeatherForecast>
<dateFormatted>string</dateFormatted>
</WeatherForecast>
The problem is that when I send that XML back to the API, it does not populate the DateFormatted property. If I change the case so that it is no longer CamelCase (DateFormatted) it works properly, and the property is populated with "string".
How do I switch off CamelCase when generating the swagger definition?
In aspnet the camelcase properties name by default so you change Startup from
services.AddMvc();
to
services
.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
Reference: aspnet
I am new for JSF. In my project am using #ManagedBean, #RequestScoped. Am using 4 pages in my project. My problem was bean values not maintain in the second, third and fourth pages. Am using getter and setter properly. If i not use #ManagedProperty the bean value maintained properly. But i need to use the
#ManagedProperty. Could you please advise me how to solve this issue. I have copied some sample code for reference.
#ManagedBean
#RequestScoped
public class ArticlePrepToolManagedBean implements Runnable, Serializable {
#ManagedProperty (value="#{param.jidName}")
private String jidName;
#ManagedProperty (value="#{param.aidName}")
private String aidName;
private List<com.elsevier.ArticlePrepTool.db.ItemZipContains> usabilityDetailList = null;
public String getAidName() {
return aidName;
}
public void setAidName(String aidName) {
this.aidName = aidName;
}
public String getJidName() {
return jidName;
}
public void setJidName(String jidName) {
this.jidName = jidName;
}
public List<ItemZipContains> getUsabilityDetailList() {
return usabilityDetailList;
}
public void setUsabilityDetailList(List<ItemZipContains> usabilityDetailList) {
ArticlePrepToolManagedBean.usabilityDetailList = usabilityDetailList;
}
}
My project url is (http://localhost:8080/articlepreptool/) but input for my project is jidName=AEA aidName=10663. that input given by some other webpage that is if user trigger using the following href "PrepTool". Depends on the input i fetched some data in my project DB (using JPA) and list out the data in the first page. But if i goes to next page all previous data stored in that list which i got from DB was cleared that is all list values and variables which set in the bean becomes null. So could you please advise me how to solve this issue.That problem occured only if i used the #ManagedProperty. I used #ManagedProperty to fetch the input values comes through url, because the input values of my project comes through other web page.
A #ManagedProperty("#{param.foo}") basically sets the HTTP request parameter with name "foo" as a bean property directly after bean's construction. If you're retrieving null values for them, then it simply means that those parameters are not present in the HTTP request.
Assuming that you're navigating by a plain link, then you need to fix your links to include the request parameters:
<h:link value="Go to page2" outcome="page2">
<f:param name="jidName" value="#{bean.jidName}" />
<f:param name="aidName" value="#{bean.aidName}" />
</h:link>
This will result in something like:
<a href="page2.xhtml?jidName=foo&aidname=bar">
This way those parameters can be set as bean properties.
Alternatively, instead of #ManagedProperty you could also use <f:viewParam> on all pages and add includeViewParams=true to the outcome. See also ViewParam vs #ManagedProperty(value = "#{param.id}")
If you're navigating by a form submit, then there's really no reason to use them. Or you must be abusing forms instead of links for plain vanilla page-to-page navigation.
HI:
When using a form,the parameter form the clien can be bound to an object,for example:
processing-forms.html
In the client:
<s:form action="register">
<s:textfield name="personBean.firstName" label="First name" />
<s:textfield name="personBean.lastName" label="Last name" />
<s:textfield name="personBean.email" label ="Email"/>
<s:textfield name="personBean.age" label="Age" />
<s:submit/>
</s:form>
In the severside:
public class Register extends ActionSupport {
private static final long serialVersionUID = 1L;
private Person personBean;
//................
}
Then the parameter of the client are bound to the personBean instance.
Now,my problem is how to bind the parameters without a from?
My action work as a service which will be called in the javascript,so how to bind them?
I know how to get the parameters:
Map(String,Object) map=ActionContext.getContext.getParameters();
String firstName= map.get("firstname")[0];
//..........
This is too ugly :(
UPDATE
public class ParaWrapper(){
private String firstName;
public void setFirstName(String ..){
this.firstName=...
}
//the getter of firstName
public ....
}
public MyAction extends ActionSupport{
private ParaWrapper wrapper;
public void setXXX()...
public void getXXX()...
public void execute(){
System.out.println(wrapper); //here I can not get the parameters,it seems that the parameters are not poputed to this object.
}
}
Since I do not use the s:form tag,so How do struts know where to put the paramters ?
You handle it the same way. If your field is named firstname, then you will need a setFirstname method on the action. Whether the parameters are coming from a form or from JavaScript is irrelevant.
Update
Based on your revised code example, you will need a getWrapper method on your action to expose the ParaWrapper object.
You can avoid the "wrapper." prefix by implementing the ModelDriven interface and making ParaWrapper your model. Then you would just have parameters such as: firstName, lastName, etc (whatever fields are on ParaWrapper).
I think you shouldn't use private fields for the values that should be set via Struts2.
Explanation:
I don't know how you post the parameters to your action via JavaScript, but it should work if you add the necessary parameters to the URL you call. You can possibly call (as suggested in the mailing list):
http://yourdomain/yourstruts.action?personBean.firstName=a_string&personBean.lastName=my_lastName& ... (more person parameters)
Struts2 will understand the dot-notation and try to set the personBean variable in your target action. If this is of a Bean class (with an empty public constructor and public setters for each parameter), it will generate a new object and call the setters with the parameters. If it cannot access the parameters, nothing can be set.
So, if your setters are public and your PersonBean class is defined correctly, a PersonBean should be in your actions personBean field.
Hope this helps.
I have a must to host WCF Service using WCF Session mechanism.
I've read http://msdn.microsoft.com/en-us/library/ms733040.aspx but it is not enough...
My simple scenearion:
I have solution with 4 projects.
First - SessionWCF.Base, it is simple Class Library that contains base interface IServiceBase for my service.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace SessionWCF.Base
{
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IServiceBase
{
[OperationContract(IsInitiating = true, IsTerminating = false)]
void BeginSession(string message);
[OperationContract(IsInitiating = false, IsTerminating = false)]
string GetMessage(int number);
[OperationContract(IsInitiating = false, IsTerminating = true)]
void EndSession();
}
}
Second - SessionWCF.Lib, it is WCF Class Library that contains service interface ISessionService and service class SessionService , it has project reference to SessionWCF.Base
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using SessionWCF.Base;
namespace SessionWCF.Lib
{
[ServiceContract(SessionMode = SessionMode.Required)]
public interface ISessionService : IServiceBase
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Activation;
namespace SessionWCF.Lib
{
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SessionService : ISessionService
{
string message = "";
#region ISessionService Members
public void BeginSession(string message)
{
this.message = message;
}
public string GetMessage(int number)
{
return "message: " + message + " number: " + number;
}
public void EndSession()
{
message = "";
}
#endregion
}
}
Third - SessionWCF.Web it is ASP.NET MVC 2.0 application that has inside SessionService.svc file. I've deleted code behind and opened XML editor, this service is pointed to service from SessionWCF.Lib, and of course this project has reference to SessionWCF.Lib.
SessionService.svc:
<%# ServiceHost Language="C#" Debug="true" Service="SessionWCF.Lib.SessionService" CodeBehind="SessionWCF.Lib.SessionService.cs" %>
Web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="SessionServiceBehavior" name="SessionWCF.Web.SessionService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="largeMessageHttpBinding" contract="SessionWCF.Lib.ISessionService">
<identity>
<dns value="**********"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://**********/SessionWCF/SessionService.svc"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="largeMessageHttpBinding" maxReceivedMessageSize="10485760">
<readerQuotas maxArrayLength="100000"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SessionServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Fourth - SessionWCF.WPF it is standard WPF application that contanins SessionProxy class and in xaml form click event to call web service. This project has project reference to first one SessionWCF.Base.
SessionProxy class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SessionWCF.Base;
using System.ServiceModel;
namespace SessionWCF.WPF
{
public class SessionProxy
{
public IServiceBase Proxy { get; set; }
public SessionProxy(string url)
{
WSHttpBinding binding = new WSHttpBinding();
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
binding.OpenTimeout = new TimeSpan(0, 1, 0);
ChannelFactory<IServiceBase> factory = new ChannelFactory<IServiceBase>(binding,
new EndpointAddress(url));
Proxy = factory.CreateChannel();
}
}
}
Click event in xaml form:
private void Button_Click(object sender, RoutedEventArgs e)
{
string url = "http://**********/SessionWCF/SessionService.svc";
SessionProxy client = new SessionProxy(url);
client.Proxy.BeginSession("my message");
string msg = client.Proxy.GetMessage(666);
client.Proxy.EndSession();
txtMsg.Text = msg;
}
Now:
When I call web service in web browser I've get following error:
Error in '/SessionWCF' Application.
Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.]
System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +16376242
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +1940
System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +64
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +287
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1132
[ServiceActivationException: The service '/SessionWCF/SessionService.svc' cannot be activated due to an exception during compilation. The exception message is: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it..]
System.Runtime.AsyncResult.End(IAsyncResult result) +890624
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +180062
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
When I call it in my xaml event I get ServiceActivationException:
The requested service, 'http://**********/SessionWCF/SessionService.svc' could not be activated. See the server's diagnostic trace logs for more information.
Is it wrong configuration in web.config?
Maybe I'm missing something in service attributes?
And the most important. Why it alerts me about BasicHttpBinding when I'm not using it ???
Any one could help me with this please? It is critical to my current project...
Regards,
Daniel Skowroński
UPDATE:
#marc_s
Firstly:
I think that server-side is wrong because when I simply paste url
'http://**********/SessionWCF/SessionService.svc' in any web browser I'll get error
"Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it. " instead metadata...
Secondly:
In my client WPF application I have always two options:
First - Create service reference and IDE will automatically generate proxy class and add all configuration to app.config.
Here I can't do that because I'm getting the same error as in web browser when I point to web service in Service Reference designer.
Second - Create poxy manually and app binding configuration from code, this gives me opportunity create proxy step by step, but it seems that ServiceActivationException it is the same problem "ACTIVATION", you can see in stack trace this lines:
[ServiceActivationException: The service '/SessionWCF/SessionService.svc' cannot be activated due to an exception during compilation. The exception message is: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it..]
System.Runtime.AsyncResult.End(IAsyncResult result) +890624
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +180062
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136
Regards,
Daniel Skowroński
UPDATE:
#marc_s
I don't this it is the case because:
Firstly:
<services>
<service name="SessionWCF.Web.SessionService"
behaviorConfiguration="SessionServiceBehavior">
Service name it is a name of web service file inside asp.net application, so it points to SessionService.svc which belongs to SessionWCF.Web assembly (the same name as project).
Secondly:
<%# ServiceHost Language="C#" Debug="true"
Service="SessionWCF.Lib.SessionService"
CodeBehind="SessionWCF.Lib.SessionService.cs" %>
Service= is a factory method that gets "type" of the service to create, it also needs class description so CodeBehind= must be pointed to SessionService.cs file where factory method can find SessionService type inside SessionWCF.Lib assembly.
Mentioned two statements are not the issue because when NOT using State Service scenario this works like a charm...
I believe that for the State Service it must me configure something more in web.config are I'm missing something in interface/class description in WCF Class Library...
I'm still in critical situation...
Regards,
Daniel Skowroński
UPDATE
#marc_s you wrote
I think you're wrong here on the SVC
file - check out:
msdn.microsoft.com/en-us/library/aa751792.aspx
- the Service=".." attribute must be "The value of the Service attribute is
the common language runtime (CLR) type
name of the service implementation." -
you need to specify the .NET name of
the service implementation class here
! That's your
SessionWCF.Lib.SessionService class.
I agree with you becouse it is exacly what I've wrote :-)
You point this article: http://msdn.microsoft.com/en-us/library/aa751792.aspx
But a few lines below and you will see what it is under the hood:
new ServiceHost( typeof( MyNamespace.MyServiceImplementationTypeName) );
So when I typed:
<%# ServiceHost Language="C#" Debug="true"
Service="SessionWCF.Lib.SessionService"
CodeBehind="SessionWCF.Lib.SessionService.cs" %>
I pointed exacly: SessionWCF.Lib - namespace, SessionService - class where I have my service implemented.
I my example SessionWCF.Lib - it is both assembly name for .dll and namespace inside SessionWCF.Lib project what you can see at the top of this post when I describe second project in my solution, starting by "Second - SessionWCF.Lib, it is ..."
And again this solution WORKS perfectly without Session functionality of WCF, but it is NOT WORKING when I use WCF Session what I need...
Thanks for engagement but issue must be elsewhere...
UPDATE 2010-07-08
#marc_s was right about wrong configuration in web.config.
Proper configuration must have to be the same name as in Wcf Library:
<service behaviorConfiguration="SessionServiceBehavior" name="SessionWCF.Lib.SessionService">
Regards,
Daniel Skowroński
#marc_s was right about wrong configuration in web.config.
Proper configuration must have to be the same name as in Wcf Library:
<service behaviorConfiguration="SessionServiceBehavior" name="SessionWCF.Lib.SessionService">
I have this working and getting data. However, everytime I page it calls the GetAllWebExceptions, which gets all of the web exceptions records from the database. How should paging be implemented? I've only seen examples with EntityFrameworks. Does anyone have a good example using the data source with POCO or is that still to come?
<Grid x:Name="LayoutRoot" Background="White">
<ria:DomainDataSource x:Name="ErrorLogDataSource"
LoadMethodName="GetAllWebExceptions">
<ria:DomainDataSource.DomainContext>
<services:CMSContext />
</ria:DomainDataSource.DomainContext>
</ria:DomainDataSource>
<data:DataGrid x:Name="DataGridExceptions" ItemsSource="{Binding ElementName=ErrorLogDataSource, Path=Data}"
AutoGenerateColumns="True">
</data:DataGrid>
<dataControls:DataPager Source="{Binding Data, ElementName=ErrorLogDataSource}"
PageSize="20" />
in the service:
[Query(PreserveName = true)]
public IEnumerable GetAllWebExceptions()
{
return WebException.SelectAll("DATECREATED DESC");
}
You should certainly be able to use a POCO class. However your query method needs to reference it by returning a generic IEnumerable, so the rest of the system knows at compile time of your type.
The requirement is your POCO class must have some notion of identity, made up of one or more members that are marked with the [Key] metadata attribute.
For example:
public class WebException {
[Key]
string id;
// Or it could be a DateTime if you use time of occurrence as the key,
// or anything else that is unique.
// ...
// Other members
}
public class ErrorManager : DomainService {
public IEnumerable<WebException> GetAllWebExceptions() {
return WebException.SelectAll("DATECREATED DESC");
}
}
Hope that helps...
Take a look at Brad Abrams excellent walk-through on using POCO with RIA Services