I have an InfoPath 2010 form that queries a web service. The web service is expecting the entire InfoPath form as an XML string parameter. By an XML string I mean the string on the format
<my:myFields xmlns:my=...>
<my:Name>UserName</my:Name>
...
</my:myFields>
The web service will then process the string and return a result to the InfoPath form.
I have tried to pass the root element, ".", but at the web service end I am receiving the values only formatted by \r\n and \t. Any idea on how to pass the XML tags and the values.
I have found a workaround by passing the list name and the form name to a web service. The web service, which is hosted in SharePoint, will then get the XML of the form.
Here is the code for reference:
public class InfoPathHelper
{
private string _listName;
private string _fileUrl;
public InfoPathHelper(string listName, string fileName)
{
_listName = listName;
_fileUrl = string.Format("{0}/{1}.xml", listName, fileName);
}
public string GetFormXml()
{
using (SPWeb web = SPContext.Current.Web)
{
SPList lib = web.Lists[_listName];
SPFile file = lib.RootFolder.Files[_fileUrl];
XmlDocument doc = new XmlDocument();
doc.Load(file.OpenBinaryStream());
return doc.OuterXml;
}
}
}
Related
I have a Restful service with Jersey where I return Json data, the problem is when I try to get the data with $.ajax I'm not able get it.
My Restful service is:
#Path("/RegistroJson")
public class RegistroJson {
#GET
#Path("/get/{param}/{param2}/{param3}")
#Produces(MediaType.APPLICATION_JSON)
public Usuario htmlHello(#PathParam("param") String nick,#PathParam("param2") String pass,#PathParam("param3") String email) {
Usuario u=new Usuario();
u.setPass(pass);
u.setUser(nick);
u.setEmail(email);
return u;
}
I need the json in the web but I'm not able to get it with this:
$.ajax({url: "http://localhost:8080/RestWebService/rest/RegistroJson/get/emilio/adf/asdf"})
I use that command with this service(http://rest-service.guides.spring.io/greeting) and it works correctly so I think the problem is in my rest service
Could you help me with this?
Thank you
If you go to this rest url with browser, do you receive json data? In $.json() you need to add an success action when your received data will be accessible. You can do this by adding to {} option success:function(f){ console.log(f) }
I am trying my first web app service using Azure services. I've created it in VS, and it works locally. All it does it return a string that says "hello user" is JSON.
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebGet(UriTemplate = "/DoWork")]
public string DoWork()
{
// Add your operation implementation here
return "hello user";
}
// Add more operations here and mark them with [OperationContract]
}
}
Problem is when I publish it, says successful. I can see it running on portal.
When I goto published site I get the standard THIS WEB APP HAS BEEN SUCCESSFULLY CREATED, but... when I add the /DoWork to the URL I get HTTP error 404.
I know I must be missing something simple...
any ideas?
you're missing the name of the service. In your case would be something like:
http://engineappservicev001.azurewebsites.net/something.svc/dowork
More info in here:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services
Is it possible to configure
where a file is uploaded to (it's currently being upload direct to the media library)
how a file is displayed in the Form Report (currently a long link string that can't be easily read nor clicked on)
which file types are allowed (e.g. images only)
how the file will be forwarded by email
We have a multi-site solution, so ideally we'd like to be able to set these on a form by form basis, but be able to configure defaults as Solution Default > Site default > Form specific.
I've already seen that there are code examples for limiting file size, which is something else we'd like to do.
So are any of these directly configurable, or will we need to code them?
Edit:
Web Forms For Marketers 2.3.0 rev.131126
Running on Sitecore 7.0 rev. 140120 (7.0 Update-4).
Yes you can define path where file will upload in case of file field.
Please see attached screenshot.
All file upload settings are located under:
/sitecore/System/Modules/Web Forms for Marketers/Settings/Field
Types/Simple Types/File Upload
The pipeline ran when a file is uploaded is "formUploadFile"; so you could reflector existing one and amend to add required changes.
To upload allowed file types use below link.
http://sitecorejunkie.com/2014/06/16/restrict-certain-files-from-being-uploaded-through-web-forms-for-marketers-forms-in-sitecore-an-alternative-approach/
here you can get idea that how you can restrict mime types in WFFM.
To send attachment in email you can create custom send email action in Sitecore and use below code
// send email with attachments
public static bool SendEmailWithAttachments(string To, string From, string Subject, string Message, string atchmnt1, string atchmnt2, string atchmnt3) {
bool result = true;
try {
MailMessage mailMsg = new MailMessage();
// mailaddress of sender
MailAddress mailFrom = new MailAddress(From);
mailMsg.From = mailFrom;
// mail addresses for recipients
string[] mailAddressList = To.Split(',');
foreach (string str in mailAddressList) {
try {
MailAddress mailTo = new MailAddress(str.Trim());
mailMsg.To.Add(mailTo);
}
catch { }
}
mailMsg.Subject = Subject;
mailMsg.Body = Message;
mailMsg.IsBodyHtml = true;
if (!string.IsNullOrEmpty(atchmnt1)) {
mailMsg.Attachments.Add(ReadAttachment(atchmnt1));
}
if (!string.IsNullOrEmpty(atchmnt2)) {
mailMsg.Attachments.Add(ReadAttachment(atchmnt2));
}
if (!string.IsNullOrEmpty(atchmnt3)) {
mailMsg.Attachments.Add(ReadAttachment(atchmnt3));
}
var smtp = new SmtpClient(Sitecore.Configuration.Settings.MailServer, Sitecore.Configuration.Settings.MailServerPort);
smtp.Send(mailMsg);
}
catch {
result = false;
}
return result;
}
// get attachement by media item id
public static Attachment ReadAttachment(string value) {
MediaItem mediaItem = null;
ItemUri itemUri = ItemUri.Parse(value);
if (itemUri != null) {
Item item = Database.GetItem(itemUri);
if (item != null) {
mediaItem = new MediaItem(item);
}
}
// create attachment using media item properties
Attachment attachment = new Attachment(mediaItem.GetMediaStream(), string.Join(".", new string[] { mediaItem.Name, mediaItem.Extension}), mediaItem.MimeType);
return attachment;
}
I have deployed a simple hello service in jboss server. I can view the wsdl file. Can someone help me with the client side. I mean how to access this service? Is there any way to access from web browser? Method deployed is
#WebMethod
public String greet( #WebParam(name = "name")
String name )
{
return "Hello" + name;
}
Try to know what is the wsdl url to access the service which you have just exposed. It might most probably be something like "http://localhost: < port-number >/ems-ejb/?wsdl"
If you type the same in the browser, you should be able to see the wsdl file (page with full of xml tags).
Once done, follow the steps provided here
Example on how to call the method once client stub is generated
String endpoint = "your wsdl url";
GreetImplServiceLocator objGreetImplServiceLocator = new GreetImplServiceLocator();
java.net.URL url = new java.net.URL(endpoint);
GreetIntf objGreetIntf = objGreetImplServiceLocator.getFaultImplPort(url);
String greetings=objFaultIntf.greet("stackoverflow");
I want to write some page with JavaFX applet. I want content on the applet to be dependent on user logged in.
I know I can call web services from JFX, but then what about login and session? Besides I think there might exist some better solutions for such communication than calling from applet a web service sitting on the machine applet comes from.
How can I do it?
You can build a servlet which returns the name of the logged in user.
Then in javafx you can use the class javafx.io.http.HttpRequest to call the servlet and read out the username. (The API also has some examples of how to use the HttpRequest)
The following javafx code prints out the return string of a Servlet:
var response: String;
def myRequest: HttpRequest = HttpRequest {
location: "http://localhost:8080/demo/foo.do";
method: HttpRequest.GET;
onInput: function(is: java.io.InputStream) {
var buff: StringBuffer = new StringBuffer();
var reader: BufferedReader
= new BufferedReader(new InputStreamReader(is));
var data: String;
while ((data = reader.readLine()) != null) {
buff.append(data);
}
response = buff.toString();
reader.close();
println(response);
}
};
myRequest.start();
EDIT: You should also take a look at this article: http://blogs.oracle.com/warren/entry/authenticating_a_javafx_application_using which shows how to access the html document and cookies from within the applet which resides on the document. That should be a very interesting approach for authentication.