WCF - TargetInvocationException was unhandled - wcf

I'm trying to create WCF to sync my mobile device with my server. When i try to click sync button it throws TargetInvocationException. Below is the Sync() method.
Code
Cursor.Current = Cursors.WaitCursor;
CustomerProxy.CustomerCacheSyncService svcProxy = new CustomerProxy.CustomerCacheSyncService();
Microsoft.Synchronization.Data.ServerSyncProviderProxy syncProxy =
new Microsoft.Synchronization.Data.ServerSyncProviderProxy(svcProxy);
// Call SyncAgent.Synchronize() to initiate the synchronization process.
// Synchronization only updates the local database, not your project's data source.
CustomerCacheSyncAgent syncAgent = new CustomerCacheSyncAgent();
syncAgent.RemoteProvider = syncProxy;
/*throws error below code*/
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
// TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
customer_ConfirmationTableAdapter.Fill(testHHDataSet.Customer_Confirmation);
// Show synchronization statistics
MessageBox.Show("Changes downloaded: " + syncStats.TotalChangesDownloaded.ToString()
+ "\r\nChanges Uploaded: " + syncStats.TotalChangesUploaded.ToString());
Cursor.Current = Cursors.Default;
Thanks.

I've recreated the Web Service again and it works now. The problem was the mobile device couldnt find my local webservice. Thanks.

Related

How can the application user save data to one of his own cloud storage?

In my cn1 application, I want to make it possible for the user to back up their own cloud storage. For example, your own Dropbox account.
I was looking for a solution on the WEB. I think what I found (dropbox-codenameone-sdk) I can only manage a known account because I need to know consumerSecret and consumerKey. When I write the code, I don't know the actual user account information.
Based on the operation of other applications, I assume I have to log in to the actual user his account (eg Dropbox).
Please help what API calls can I do this.
Use the Share API in Display. You can zip the data using the zip cn1lib and save it in a file within the file system then use the share API to let the user pick a native app to share it with. On the simulator it will have options such as email/facebook but on the device you should have more options.
I think I'm using the API properly. Although I did not set correctly the file access on my phone.
However, the error occured in the simulator.
The mail and DropBox sharing on my android phone is successful.
I don't like the file getting a prefix (IMG_20200112_204126_). Can I change this?
I include screenshots and a code snippet.
Best regards, Péter
public ShareForm(Resources resourceObjectInstance, Form parentForm) {
this.parentForm = parentForm;
this.theme = resourceObjectInstance;
Layout layout = new BoxLayout(BoxLayout.Y_AXIS);
setLayout(layout);
getToolbar().setBackCommand("", e -> {
this.parentForm.showBack();
});
/* file exist on simulator */
/* String filePath = FileSystemStorage.getInstance().getAppHomePath() + "temp/vendeg_201807011754.json"; */
/* file exist on phone */
String filePath = "file:///storage/emulated/0/Download/stratos.pdf";
String mimeType = "application/octet-stream";
boolean exist = FileSystemStorage.getInstance().exists(filePath);
long size = FileSystemStorage.getInstance().getLength(filePath);
SpanLabel spanLabel0 = new SpanLabel("File path: " + filePath);
SpanLabel spanLabel1 = new SpanLabel("File exist: " + exist);
SpanLabel spanLabel2 = new SpanLabel("File size: " + size);
ShareButton shareButton = new ShareButton();
shareButton.setText("Share data (ShareButton)");
shareButton.addActionListener(e-> {
shareButton.setImageToShare(filePath, mimeType);
shareButton.actionPerformed(e);
});
Button shareButton1 = new Button("Share data (Share API in Display)");
FontImage.setMaterialIcon(shareButton1, FontImage.MATERIAL_SHARE);
shareButton1.addActionListener(e -> {
Display.getInstance().share(null, filePath, mimeType, shareButton1.getBounds(new Rectangle()));
});
addComponent(spanLabel0);
addComponent(spanLabel1);
addComponent(spanLabel2);
addComponent(shareButton);
addComponent(shareButton1);
}

How to backup and restore sessions on Fiddler startup and shutdown?

What I want is backup all sessions at Fiddler shutdown and when I turn it on again it needs to load that sessions again.
I managed to change the FiddlerScript by creating a save action and dump all sessions with this:
case "save":
FiddlerObject.UI.actSelectAll();
FiddlerObject.UI.actSaveSessionsToZip(CONFIG.GetPath("Captures") + "saved.saz");
FiddlerObject.StatusText = "Saved in " + CONFIG.GetPath("Captures") + "saved.saz";
break;
It works fine and all currently loaded sessions are saved.
I tried to create a action to restore them but it does nothing (I loaded the session but don't know how to get back in the grid):
case "restore":
//I don't know what I need to do with this
Utilities.ReadSessionArchive(CONFIG.GetPath("Captures") + "saved.saz", true);
break;
After that I want to do something similar do execute them with ExecAction at startup and shutdown but this is another part of my puzzle.
TL;DR
How to restore a previously saved dump using FiddlerScript on startup?
Rules > Customize Rules.
Update the OnBoot and OnShutdown functions thusly:
static function OnBoot() {
FiddlerApplication.UI.actLoadSessionArchive("_stored.saz");
}
static function OnShutdown() {
FiddlerApplication.UI.actSelectAll();
var sFilename = (CONFIG.GetPath("Captures") + "_stored.saz");
FiddlerApplication.UI.actSaveSessionsToZip(sFilename);
}

Play app failing with no exception thrown

I have a play application running on a linux server. The play application handles an ajax request, the controller code that handles the request :
public static Result getStorageId() {
final String host = request().username();
logger.debug("get storage id from origin:" + host);
Promise<Product> promiseProduct = Akka.future(new Callable<Product>() {
#Override
public Product call() throws Exception {
Partner partner = PartnerModel.getPartner(host);
logger.debug("Partner origin:" + partner.getHost());
** Product productCase = ProductsModel.createProduct();
logger.debug("product created. id:" + productCase.getId());
return productCase;
}
});
return async(promiseProduct
.map(new Function<Product, Result>() {
#Override
public Result apply(Product product) {
return ok();
}
}));
}
The ProductsModel.createProduct() code is
public static Product createProduct(){
logger.debug("creating new product");
Product product = new ProductImpl();
saveProduct(product);
return product;
}
The issue is when an ajax request made the app reaches line ** and stops but there's no error indicated in the application.log file nor in the play console. The debug statement in the first line of createProduct() method is not executed. The app is still running as I can make another ajax request and see the log statement before line **.
I did try "play run" hoping that it might give more info since it runs in debug mode but no luck.
My local development copy works fine. Another thing, I had this issue before and as a desperate attempt I just create a new class "ProductTestModel" with the same functionality as ProductsModel and used it instead of ProductsModel (ie on line ** it goes Product productCase = ProductTestModel.createProduct() ) deployed it and everything worked. Now after several releases I get this problem again.
I'm using GIT to distribute the code to the server and have play compile the app there. Running play clean compile shows no errors.
So what could be the problem?
I found out the root cause of my problem. It's actually a stupid thing, I forgot to include a conf file. Where the code was failing that object was using that conf file.
Talk about hours being wasted!!

Trouble Attaching File Programmatically to Email in Windows Metro App C#/XAML using Share Charm

I'm simply trying to attach a file named Document.pdf in the DocumentsLibrary to an email using the Share Charm. My code below works perfectly on the Local Machine:
private async void OnDataRequestedFiles(DataTransferManager sender, DataRequestedEventArgs e)
{
List<IStorageItem> shares = new List<IStorageItem>();
StorageFile filetoShare = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync("Document.pdf");
if (filetoShare != null)
{
shares.Add(filetoShare);
filetoShare = null;
}
if (shares != null)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Title";
requestData.Properties.Description = "Description"; // The description is optional.
requestData.SetStorageItems(shares);
shares = null;
}
else
{
e.Request.FailWithDisplayText("File not Found.");
}
}
But when I run the exact same code on a Windows Surface Tablet, I get the dreaded "There's nothing to share right now." on the right in the Charms flyout area.
Here's a little more background to help:
I'm not looking to use a File Picker...I know the exact file I'm looking for
I've enabled the Documents Library Capability in the manifest
I've added a File Type Association for pdf in the manifest
and yes, the file does exist and is in the Documents Library
an email account is properly setup in the Mail App on the surface
I can successfully send text emails from the Tablet...just not emails with attachments
Like I said, this works on my Win 8 Development Machine as expected...just not on the Surface. I'm wondering if the Surface has different file or folder permissions?
Thanks for the help...this is driving me CRAZY
I finally figured it out - the problem was that my Event Handler was async (so that I could use await to set the StorageFile variable).
I solved it by setting the StorageFile variable earlier in my code so that it was already available when the Event Handler was called.
I still have no idea why it worked on my development machine, but no on the WinRT surface...
The handler can be an async method. In this case, it is critical to use DataTransferManager. Please refer to the MSDN page specifically for this scenario. For your convenience, the code from the page is copied to here:
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
}
private async void ShareStorageItemsHandler(DataTransferManager sender,
DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share StorageItems Example";
request.Data.Properties.Description = "Demonstrates how to share files.";
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
It is critical to place the following statement before any async method is called:
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
You only have half a second to get the whole job done (getting the file, attaching...etc.). If the half-second deadline occurs you'll get this "driving crazy" message. Consider implementing some resumable logic and replace the message with "the attachment is being prepared please try again in a few seconds" (or else).
Your WinRT device might be just slower than your development machine. The latter just does the job before the deadline...

Sync Services for ADO.NET Solution for Mobile Devices - ArgumentNullException

I'm trying to create a sync between my mobile and database server. I am following this tutorial and it get ArgumentNullException Value can not be null.
Parameter name: ServerSyncProvider in sych() function.
Code
private void Sync()
{
Cursor.Current = Cursors.WaitCursor;
WebReference.NorthwindCacheSyncService svcProxy = new WebReference.NorthwindCacheSyncService();
Microsoft.Synchronization.Data.ServerSyncProviderProxy syncProxy =
new Microsoft.Synchronization.Data.ServerSyncProviderProxy(svcProxy);
// Call SyncAgent.Synchronize() to initiate the synchronization process.
// Synchronization only updates the local database, not your project's data source.
NorthwindCacheSyncAgent syncAgent = new NorthwindCacheSyncAgent();
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
// TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
// Show synchronization statistics
MessageBox.Show("Changes downloaded: " + syncStats.TotalChangesDownloaded.ToString()
+ "\r\nChanges Uploaded: " + syncStats.TotalChangesUploaded.ToString());
Cursor.Current = Cursors.Default;
}
As the error says "Value can not be null. Parameter name: ServerSyncProvider"
Means it is not initialized
You have missed one line of code inbetween
NorthwindCacheSyncAgent syncAgent = new NorthwindCacheSyncAgent();
syncAgent.RemoteProvider = syncProxy
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();