Cannot send Email in custom workflow sharepoint 2010 - c#

I have some trouble when using SPUtility.SendEmail method in a custom workflow.
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
if (SPUtility.IsEmailServerSet(workflowProperties.Site.OpenWeb()))
{
StringDictionary headers = new StringDictionary();
headers.Add("to", "myemailaddress#mailinator.com");
headers.Add("from", "somebody#example.com");
headers.Add("content-type", "text/html");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
bool test = SPUtility.SendEmail(web, headers, "some message body");
});
}
}
in the code's above, the method SPUtility.SendEmail always returning false.
I've even tried to use RunWithElevatedPrivileges, but still the method returns false.
The smtp configuration is not the problem, because the standard email notification when a task is assigned in sharepoint is sent all right.
The strange part is, I have tried this SendEmail method using a timer job, and the method is working perfectly fine.
please somebody help me if there is something i need to add to my method's above.
thanks.

Try to get the web reference in the elevated privileges scope.

I couldn't find the root of this problem.
I decided to do create 2 workflow: the first is to send the email using initiation parameter (build using sharepoint designer). the second one is workflow that initiate the first workflow.
it's now up and running.

Related

How To Pass Two Parameters In "Client.WriteLine" In "SimpleTCP"

So I want to make a chat application in C# using the NuGet module "SimpleTCP", I made it work so the clients can send messages to the server and all clients get those messages but what I want now is to make it so I could pass a name string in the client.WriteLine("Message") when I send a message to the server telling a message was sent("client" is my "SimpleTcpClient" variable).
The problem is that the "WriteLine()" function get only ONE argument so it can't get a Message and Name variables.
I have tried searching google for a solution for that but found nothing.
I also tried just doing "client.WriteLine("This is a message", "Tal M")" but it didn't work.
This is some of the code that tells the client to send a message to the server:
private void SendMessageInput_Click(object sender, EventArgs e)
{
client.WriteLine(MessageInput.Text);
}
This is the lines that makes the server get the message and broadcast it to all other(including the client that send the message) clients:
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
txtStatus.Invoke((MethodInvoker)delegate ()
{
txtStatus.Text += e.MessageString;
server.Broadcast(String.Format(e.MessageString));
});
}
What I expect is to be able to get a message that includes Two arguments; First one for a message(String), and Second one for a name(String). I would really appreciate getting help, Thanks.
So I found a solution for my problem! All I had to do is just format the String that I send so it would include both Name and Message using client.WriteLine(String.Format("{0}: {1}", "Bob", "Hello World")).
This solution isn't great since I might need to change it to actually get the Name and Message as variables. If I would want to do that I would need to send a JSON object which can work really well but I don't want to do it now(This solution was suggested by #Sir Rufo, Thanks for the help.

Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException Trying to Read Email From EWS C#

I'm Developing a Console Application for testing purpose in C#. This Application is made to read the Email from MS Exchange Web Service server2007. But I can't get it working for a while. should I include some code in the App.config? which one!
here is this exception
AutodiscoverLovalException
Even I make use of configurattion.appSettings() to pass the key and the value, Still getting the same handler. this really frustrate a lot.
Here is my tested code:
static void Main(string[] args)
{
// Create the binding.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user", "pass", "domain");
// Set the URL.
service.AutodiscoverUrl("user#domain.com",);
}
static bool RedirectionCallback(string url)
{
return url.ToLower().StartsWith("https://");
}
Anyone have an idea?
In your given code, you do not call the method RedirectionCallback.
Edit line 8 to the following:
service.AutodiscoverUrl("user#domain.com", RedirectionCallback);

Adobe AIR & Web Service Call. Errors with Error #1085: The element type "br" must be terminated by the matching end-tag "</br>"

Here is my simple code, which works fine if called from php or any other client then adobe air. Same code also works from calling from SWF, there is fluorineFX code for other part of project as well, but then it doesn't do anything to break this.
I do find one thing that all POST calls were somehow changing to GET, which really amazes me. I would be so glad to get the answer for this. Thanks in Advance everyone. Below is the almost same code from my web service. with AIR code just under it.
[WebMethod(EnableSession = true)]
public bool Authenticate(string UserName,string Password)
{
try
{
if (Membership.ValidateUser(UserName, Password)){
FormsAuthentication.SetAuthCookie(UserName, true);
return true;
}
return false;
}
catch (Exception ex)
{
return false;
}
}
and my call from adobe AIR code as below
var ws:WebService = new WebService();
ws.wsdl="http://mysite.com/myservice.asmx?WSDL";
ws.useProxy=false;
ws.addEventListener(LoadEvent.LOAD,onWSDLLoad);
ws.loadWSDL();
ws.Authenticate.addEventListener(ResultEvent.RESULT,resultHandler);
ws.Authenticate.addEventListener(FaultEvent.FAULT,onLoginFaultHandler);
ws.Authenticate("usrname","password");
protected function onLoginFaultHandler(event:FaultEvent):void
{
Alert.show('Login Failed with messsage\r\n[ '+event.fault.faultString+' ]');
/* Error #1085: The element type "br" must be terminated
by the matching end-tag "</br>". */
/* checking the content value of fault event shows
same out put as http://mysite.com/myservice.asmx */
}
protected function onLoginResultHandler(event:ResultEvent):void
{
/* on success code */
}
This guy tells us following in page http://verveguy.blogspot.com/2008/07/truth-about-flex-httpservice.html
All HTTP GET requests are stripped of headers. It's not in the Flex stack so it's probably the underlying Flash player runtime.
All HTTP GET requests that have content type other than "application/x-www-form-url-encoded" are turned into POST requests
All HTTP POST requests that have no actual posted data are turned into GET requests. See 1/ and 2/
All HTTP PUT and HTTP DELETE requests are turned into POST requests. This appears to be a browser limitation that the Flash player is stuck with.
I do see my request above turns into GET, but then I DO have post values in it. OR if those are somehow are not sent or recorded by Web Service Object ?
This is pretty simple... The Flex XML parser uses strict xml checking, so all tags must be closed. If you can change the web service, then change all <br> tags to <br />.
I finally found the answer myself. turns out I was having cookies set to AutoDetect. Which meant that the AIR would call a URL and it would need to redirect to keep the cookie/session value in side the URI itself.
Now I switched that to UseCookies and Everything is back to normal. I could test this from a sample web services and realized it was the server-side that was doing something wrong. And from AIR to Browser that's the only difference of cookies.
Somehow nusoap for PHP is smart to know that there is AutoDetect or New URI of the Web Services available. But AIR couldn't locate that. Anyways Thanks everyone for helping me solve this.

Need some help with code for getting a response from a Web service. Can you help me connect the dots?

Ok, its been a while since I've worked with a Web References. I need a refresher. I think I have about 80% of the code I need to get a response going but I'm missing something. Maybe you can help me :)
Given:
A web method called GetSomething in the list of methods when pointing to a .wsdl url.
This produces a few classes/objects:
GetSomethingRequest
GetSomethingCompletedEventHandler
GetSomethingCompletedEventArgs
myComplexType
Which I use to create this code:
void someMethodToTestResponse()
{
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;
//.... ok now what?
//handler.Invoke(???)
// at this point I'm supposed to send an object for source (request maybe?)
// and a new instance of GetSomethingCompletedEventArgs but that class is
// asking for stuff that makes me think that is not the right idea.
}
void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
// get the result
var result = args.Result;
}
What am I doing wrong? What am I missing? Thanks in advance.
You don't need web service source codes. The web service can be implemented in Java. Creating service reference woks the same, as we really don't know what is on the other side.
So, try Add Service Reference in VS2008 and enter the url to working web service. VS will examine the wsdl on server and generate needed classes for you.
From than on, you just call the service as some ordinary method call. Meaning you don't have to fiddle with requests and http and such details. All that is hidden from you. Except in app.config where many WCF settings can be changed.
Ok, I figured out that I needed to find a Service type class. See this SO Post where it mentions:
private com.nowhere.somewebservice ws;
The issue was that the class they provide wasn't intellisensing for me and I figured it wasn't what I was looking for.
Here is how I would solve my problem:
blah.webservice.SomeMainServiceClass service = new SomeMainServiceClass();
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
object myResponse = service.GetSomething(request);

Consuming a void service operation in a WCF data service

from a Wcf data service client (inherited from System.Data.Services.Client.DataServiceContext) I would like to invoke a service operation defined on a Wcf Data Service that returns void
[WebGet]
public void Operation()
{
// logic
}
The only reasonable method I found is the Execute, but how could I use it with a void operation?
Thank you
You can use just plain HttpWebRequest to do this. I think it will need to be POST service operation (as GET would assume some response, but since you declare it as void it would have no response). In which case Execute can't be used anyway (as it always issues a GET request).
Using plain HttpWebRequest just issue a simple POST to the service operation URL and just check the response status code (should be 204 No Content).
Currently WCF Data Services doesn't have native client support for service operations, so you need to write one for yourself.
I have found a workaround for this problem.
This website solved me quite a few problems before, so I thought it would be nice to share back.
The quick answer to your question is:
string empty = context.Execute<string>(new Uri("Operation", UriKind.Relative)).FirstOrDefault();
The "empty" string should be null or empty upon response. It "works around" the HttpWebRequest method mentioned on the post above.
Further more, it is also possible to get primitive types back using this technique.
Lets say I have this Method:
[WebGet]
public bool Authenticate(string Username, string Password)
{...do stuff here...}
When you try the normal execution it fails (Vitek Karas explains it well in his reponse above):
var query = context.CreateQuery<bool>("Authenticate").AddQueryOption("Username", "'itye'").AddQueryOption("Password","'123456'");
DataServiceCollection<bool> list = new DataServiceCollection<bool>();
list.Load(query);
But the following will do the trick:
var query = context.CreateQuery<bool>("Authenticate").AddQueryOption("Username", "'itye'").AddQueryOption("Password","'123456'");
bool authenticated = context.Execute<bool>(new Uri(query.RequestUri.ToString().Replace("Authenticate()", "Authenticate"))).FirstOrDefault();
Please note the Replace("Authenticate()", "Authenticate"), which omits () from the query string (otherwise it will cause error).
Hope it helps.
- Itye
Thanks Itye
I was looking for similar solution. Did using HttpWebRequest way first. But your two lines of code helped me doing the same task. Very Happy. Thanks Once Again..
var query = context.CreateQuery("Authenticate").AddQueryOption("Username", "'itye'").AddQueryOption("Password","'123456'");
bool authenticated = context.Execute(new Uri(query.RequestUri.ToString().Replace("Authenticate()", "Authenticate"))).FirstOrDefault();

Categories

Resources