Custom Workflow shows Error on Passing Parameters - microsoft-dynamics

Dynamics CRM 365
In Custom Action Add a step of CustomWorkflow
without Parameters CustomWorkflow Execute successfully
but with parameters shows Error
" System.AggregateException: One or more errors occurred."
protected override void Execute(CodeActivityContext context)
{
ITracingService _tracer = context.GetExtension<ITracingService>();
IWorkflowContext _workflowContext = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory _serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService _service = _serviceFactory.CreateOrganizationService(_workflowContext.UserId);
try
{
string _emailId = EmailID.Get<string>(context);
throw new InvalidPluginExecutionException("An Error Occured" + _emailId);
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An Error Occured in Followup Plugin!", ex);
}
catch (Exception ex) {
_tracer.Trace("Exception", ex.ToString());
throw;
}
}
[Input("EmailID")]
public InArgument<string> EmailID { get; set; }
[Input("SubPoId")]
public InArgument<string> SubPOId { get; set; }

What if you remove <string> so your line reads:
string _emailId = EmailID.Get(context);

Related

I cannot make a cast from unbounded wildcard to a specific List<Game>

I tried this in my controller class:
#Override
public void initialize(URL location, ResourceBundle resources) {
try {
games = (List<?>) fr.readFile();
#SuppressWarnings("unchecked")
List<GameImpl> games2 = (List<GameImpl>) games;
} catch (IOException e) {
System.out.println("err");
throw new RuntimeException(e);
}
but when I try to access games2 function, an Exception occurred

Unit testing ExceptionFilterAttribute

I'm trying to unit test my exception filter code. I can validate the exception, but I can't seem to find the exception message to validate in the unit test. Here is my code...
public class ExceptionHandlingAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
if (context.Exception is TimeoutException)
{
context.Response = context.Request.CreateErrorResponse(HttpStatusCode.RequestTimeout, context.Exception.Message);
return;
}
if (context.Exception is UnauthorizedAccessException)
{
context.Response = context.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, context.Exception.Message);
return;
}
context.Response = context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to process your request.");
}
}
Unit Test Code
[Theory, MemberData("ExceptionData")]
public void OnExceptionTests(Exception ex, HttpStatusCode statusCode)
{
var request = new HttpRequestMessage();
var actionContext = InitializeActionContext(request);
var httpActionExectuedContext = new HttpActionExecutedContext(actionContext, ex);
var exceptionHandlingAttribute = new ExceptionHandlingAttribute();
exceptionHandlingAttribute.OnException(httpActionExectuedContext);
Assert.Equal(actionContext.Response.StatusCode, statusCode);
Assert.Equal(actionContext.Response.ReasonPhrase, ex.Message);
}
public static IEnumerable<object[]> ExceptionData
{
get
{
return new[]
{
new object[] { new TimeoutException("My timeout message."), HttpStatusCode.RequestTimeout }
};
}
}
My problem is : Assert.Equal(actionContext.Response.ReasonPhrase, ex.Message);
When I try to look at it in the watch window, I can't seem to find "My Timeout message" in the response.
UPDATE:
actionContext.Response.ReasonPhrase = "Request Timeout"
ex.Message = "My timeout message"
The message portion of the CreateErrorResponse isn't a property, you have to read the content to get the value. Here's what I did...
var responseContent = await actionContext.Response.Content.ReadAsStringAsync();
After reading, responseContent now had:
{ "message" : "My timeout message." }

Send XML document in the HTTP body

I have a Web API controller with method
public IHttpActionResult Get(int id)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("test.xml");
return Ok(xmlDoc.InnerXml);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
The XML document show as string in the HTTP message body
"<?xml version=\"1.0\" encoding=\"utf-8\"?><TestInfo xmlns=\"http://myschema\"><ID>171961</CSOSAID>...</TestInfo>"
I want it to be in simple XML like
<?xml version="1.0" encoding="utf-8"?><TestInfo xmlns="http://myschema"><ID>171961</ID>...</TestInfo>
How could I do it? Try several ways but couldn't get? Thanks.
You are serializing the String object using an XMLSerializer which is not what you want.
You can do this,
public IHttpActionResult Get(int id)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("test.xml");
return new ResponseMessageResult(new HttpResponseMessage() {Content = new StringContent(xmlDoc.InnerXml, Encoding.UTF8,"application/xml")});
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
or you can create your own IHttpActionResult helper class, like this,
public class XmlResult : IHttpActionResult
{
private readonly XmlDocument _doc;
public XmlResult(XmlDocument doc)
{
_doc = doc;
}
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
return
Task.FromResult(new HttpResponseMessage()
{
Content = new StringContent(_doc.InnerXml, Encoding.UTF8, "application/xml")
});
}
}
which would then allow you to do,
public IHttpActionResult Get(int id)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("test.xml");
return new XmlResult(xmlDoc);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
or you could switch to XElement which will magically do the right thing,
public IHttpActionResult Get(int id)
{
try
{
XElement xElement = XElement.Load(..);
return OK(xElement);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
You can find more details on why the behaviour is the way it isin this blog post http://www.bizcoder.com/posting-raw-json-to-web-api

how to get contacts list from google glass using GDK

I'm implement Google Glass app.
I want to get contacts list from google glass using GDK.
I already tried contacts Api v3 (ContactsService)
but i failed because -
i can't scrolling & tapping(click) pop-up (OK Button) after glass update XE16
-> run to android phone is ok.
i tried
mirror api. device OAuth.... -> no example.. i don't know how...
if you have sample code, As it is also upload. Would you? I'd appreciate that.
here is my code.
public class MainActivity extends Activity
{
private Account[] accounts;
private AccountManager mManager;
private ContactsService mService;
private URL feedUrl;
private final String url = "https://www.google.com/m8/feeds/contacts/default/full";
private final String ACCOUNTS_TYPE = "com.google";
private final String AUTH_TOKEN_TYPE = "cp";
private String mToken;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mManager = AccountManager.get(this);
accounts = mManager.getAccountsByType(ACCOUNTS_TYPE);
Log.d("account", ""+accounts[0]);
mManager.getAuthToken(accounts[0], AUTH_TOKEN_TYPE, null, this, new AccountManagerCallback<Bundle>()
{
public void run(AccountManagerFuture<Bundle> future)
{
try
{
mToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
GetTask task = new GetTask();
task.execute(mToken);
}
catch (OperationCanceledException e)
{
e.printStackTrace();
}
catch (AuthenticatorException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}, null);
}
public void createService(String token) throws IOException, ServiceException
{
mService = new ContactsService("contacts_list");
mService.setUserToken(token);
feedUrl = new URL(url);
ContactFeed resultFeed = (ContactFeed)mService.getFeed(feedUrl, ContactFeed.class);
for (ContactEntry entry : resultFeed.getEntries()) getContacts(entry);
}
private class GetTask extends AsyncTask<String, Void, Void>
{
#Override
protected Void doInBackground(String... params)
{
try
{
String token = "";
if(params != null)
{
for(String s : params) token += s;
}
createService(token);
}
catch (ServiceException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
}
public void getContacts(ContactEntry entry) throws ServiceException, IOException
{
if (entry.hasName())
{
Name name = entry.getName();
if (name.hasFullName())
{
String fullName = name.getFullName().getValue();
Log.d("name", fullName);
}
}
else Log.d("name", "no name");
if (entry.hasPhoneNumbers())
{
for (PhoneNumber phone : entry.getPhoneNumbers())
{
String phoneNum = phone.getPhoneNumber();
Log.d("phone", phoneNum);
}
}
else Log.d("phone", "no phone");
}
}

uploading file from backberry to web service = JVM error 104 Uncaught NullPointerException?

I am developing a small blackberry project.
Here are the step that it is supposed to be:
User clicks Speak! button. The application record speech voice. [No Problem]
When user finishes speaking, click Stop! button. Once the stop button is clicked, the speech voice will be saved on BB as an AMR file. Then, the file will be sent to web service via ksoap2. Web service will return response as a string of file name. The problem is web service return nothing and there is an error occur: JVM error 104: Uncaught NullPointerException I wonder if I placed the code on the right place, or I did something wrong with ksoap2??
here is the code for web service
namespace VoiceServer
{
/// <summary>
/// Converting AMR to WAV
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
public string UploadFile(String receivedByte, String location, String fileName)
{
String filepath = fileName;
/*don't worry about receivedByte and location, I will work on them after the problem is solved :) */
return "Success"+filepath;
}
private void InitializeComponent()
{
}
}
}
Below is the code running on Eclipse, I'm not sure if I placed the code for sending file to web service on the right place.
public class MyAudio extends MainScreen {
private ButtonField _startRecordingButton;
private ButtonField _stopRecordingButton;
private HorizontalFieldManager _fieldManagerButtons;
private VoiceNotesRecorderThread _voiceRecorder;
private LabelField _myAudioTextField;
private DateField hourMin;
private long _initTime;
public MyAudio() {
_startRecordingButton = new ButtonField("Speak!", ButtonField.CONSUME_CLICK);
_stopRecordingButton = new ButtonField("Stop!", ButtonField.CONSUME_CLICK);
_fieldManagerButtons = new HorizontalFieldManager();
_voiceRecorder = new VoiceNotesRecorderThread(500000,"file:///store/home/user/voicefile.amr",this);
_voiceRecorder.start();
myButtonFieldChangeListener buttonFieldChangeListener = new myButtonFieldChangeListener();
_startRecordingButton.setChangeListener(buttonFieldChangeListener);
_stopRecordingButton.setChangeListener(buttonFieldChangeListener);
_fieldManagerButtons.add(_startRecordingButton);
_fieldManagerButtons.add(_stopRecordingButton);
_myAudioTextField = new LabelField(" Welcome to VoiceSMS!!!" );
add(_fieldManagerButtons);
add(_myAudioTextField);
SimpleDateFormat sdF = new SimpleDateFormat("ss");
hourMin = new DateField("", 0, sdF);
hourMin.setEditable(false);
hourMin.select(false);
_initTime = System.currentTimeMillis();
add(hourMin);
}
public void setAudioTextField(String text) {
_myAudioTextField.setText(text);
}
public void startTime() {
_initTime = System.currentTimeMillis();
hourMin.setDate(0);
}
public void updateTime() {
hourMin.setDate((System.currentTimeMillis()-_initTime));
}
class myButtonFieldChangeListener implements FieldChangeListener{
public void fieldChanged(Field field, int context) {
if(field == _startRecordingButton) {
try {
_voiceRecorder.startRecording();
} catch (IOException e) {
e.printStackTrace();
}
}else if(field == _stopRecordingButton) {
_voiceRecorder.stopRecording();
//----------Send AMR to Web Service-------------//
Object response = null;
String URL = "http://http://localhost:portnumber/Service1.asmx";
String method = "UploadFile";
String NameSpace = "http://tempuri.org/";
FileConnection fc = null;
byte [] ary = null;
try
{
fc = (FileConnection)Connector.open("file:///store/home/user/voicefile.amr",Connector.READ_WRITE);
int size = (int) fc.fileSize();
//String a = Integer.toString(size);
//Dialog.alert(a);
ary = new byte[size];
fc.openDataInputStream().read(ary);
fc.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
SoapObject client = new SoapObject(NameSpace,method);
client.addProperty("receivedByte",new SoapPrimitive(SoapEnvelope.ENC,"base64",Base64.encode(ary)));
client.addProperty("location","Test/");
client.addProperty("fileName","file:///store/home/user/voicefile.amr");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = client;
HttpTransport http = new HttpTransport(URL);
try
{
http.call(method,envelope);
}
catch(InterruptedIOException io)
{
io.printStackTrace();
}
catch (IOException e)
{
System.err.println(e);
}
catch (XmlPullParserException e)
{
System.err.println(e);
}
catch(OutOfMemoryError e)
{
System.out.println(e.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
response = envelope.getResponse();
Dialog.alert(response.toString());
}
catch (SoapFault e)
{
System.err.println(e);
System.out.println("Soap Fault");
}
catch(NullPointerException ne)
{
System.err.println(ne);
}
Dialog.alert(response.toString());
//Dialog.alert("Send Success");
//----------End of Upload-to-Web-Service--------//
}
}
}
}
I don't know if the file is not sent to web service, or web service has got the file and produce no response??? I am a real newbie for BB programming. Please let me know if I did anything wrong.
Thanks in advance!!!
There is a typo in your URL variable value.
"http://" typed twice
String URL = "http://http://localhost:portnumber/Service1.asmx";
Hooray!!! Problem Solved!
just changed URL as Rafael suggested and added [WebMethod] above "public string UploadFile" in the web service code