Silverlight and Windows Workflow Foundation - silverlight

private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
xxxxxxx.Workflow1_WebServiceSoapClient zer = new xxxxx.Workflow1_WebServiceSoapClient();
zer.demanderSubmitReportCompleted += new EventHandler<xxxxxxxxxxxxxxx.demanderSubmitReportCompletedEventArgs>(service2);
zer.demanderSubmitReportAsync("zzz", 20000);
}
public void service2(object sender, xxxxx.demanderSubmitReportCompletedEventArgs e)
{
string a = e.Result;
}
I'm trying to call a Windows Workflow Foundation published as a web service from a Silverlight project. When I call it from a console application it works fine because I can add a web reference then I just make an instance of that webservice then I invoke the method I want. The problem is in the Silverlight project because I can just add a service reference so I find myself working with SOAP stuff that doesn't work at all, and here is the code error:
Here is the code: I change it a litle bit in English.
Error in exécution Microsoft JScript: Unhandled Error in Silverlight Application exception happened in the operation, résult not valide. Consult InnerException for more information. in System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
in AEDSilverlightIntegrated.ServiceReference2.demanderSubmitReportCompletedEventArgs.get_Result()
in AEDSilverlightIntegrated.SilverEntryAedHeaderNew.mmm_demanderSubmitReportCompleted(Object sender, demanderSubmitReportCompletedEventArgs e)
in AEDSilverlightIntegrated.ServiceReference2.Workflow1_WebServiceSoapClient.OndemanderSubmitReportCompleted(Object state)

Well, I found a solution and I want to share it with all of you. The solution is to build a web service that works as a bridge between Windows Workflow Foundation published as a web service and a Silverlight application. Not so genious, but this resolve the problem.

First things first. Make sure that the service exposes a cross-domain policy file to allow Silverlight to make the cross-domain call.
This is only required if the service is on a different domain to the Silverlight host page.

Related

Consume SOAP Web Service in Silverlight

I'm attempting to consume a SOAP service in a Silverlight 5 application and I'm completely lost. This is my first Silverlight app and only my second time using web services in a .NET application.
In a separate .NET application, the only way I was able to get it to work was by adding the WSDL as a Web Reference; the application would not build when I added it as a Service Reference. In talking to the WSDL provider, I discovered that the WSDL was compiled using the .NET 2.0 framework...hence the need to add it as a Web Reference.
From the research I've done thus far, I see that Silverlight doesn't support adding a Web Reference. So I tried adding it to the hosting ASP.NET application as a Web Reference then started the server.
Back in my Silverlight app, I selected the option to add a Service Reference and pointed to the WSDL file now at http://localhost:55265/Web%20References/THINKWebService/SLWebSvc_734_Upgrade.wsdl. Visual Studio seemed to pick it up just fine and generate the proxies.
Here's where I start to get stuck. If my research is correct, a WCF reference was created and should be used in that manner. I've never used WCF so I did some reading on how to send/receive requests and this is the best code I've come up with, based on examples in the MSDN library (I inserted it into a button click event so I would know exactly when the code was executing):
private void Button1Click(object sender, RoutedEventArgs e)
{
var client = new ThinkSoapClient();
var userLoginData = new user_login_data {login = "foo", password = "bar"};
var customerIdentifier = new customer_identifier {customer_id = 6677070};
// the debugger halts on this next line and
// references the "dsn"...it's the 4th argument
client.CustomerLoginInfoSelectAsync(userLoginData, customerIdentifier, "", "myDSN");
// I'm not sure if this next line is even needed
client.CustomerLoginInfoSelectCompleted += CustomerLoginInfoSelectCallback;
MessageBox.Show(string.Format("CustomerLoginInfoSelectAsync({0},{1})", userLoginData, customerIdentifier));
}
// here's the callback method
static void CustomerLoginInfoSelectCallback(object sender, CustomerLoginInfoSelectCompletedEventArgs e)
{
MessageBox.Show(string.Format("CustomerLoginInfoSelect Result: {0}", e.Result));
}
As I mentioned in the code above, the debugger halts when executing the client.CustomerLoginInfoSelectAsync method. Here's the error message: XmlSerializer attribute System.Xml.Serialization.XmlAttributeAttribute is not valid in dsn. Only XmlElement, XmlArray, XmlArrayItem and XmlAnyElement attributes are supported when IsWrapped is true.
From the research I've done, I think this error is being caused because the the SOAP action element contains an attribute dsn (not sure, though, if I would be getting this error if the sub-elements also had attributes).
I did a find/replace for IsWrapped=true to IsWrapped=false in Reference.cs but I got the same error but the last word was false instead of true.
I'm not sure if I'm making any sense as to what I'm after, so here's what the generated XML should look like in case it helps:
...
<customer_login_info_select_request dsn="myDSN">
<user_login_data>
<login>foo</login>
<password>bar</password>
</user_login_data>
<customer_identifier>
<customer_id>6677070</customer_id>
</customer_identifier>
<login/> <!--corresponds to the empty string in the call to CustomerLoginInfoSelectAsync-->
</customer_login_info_select_request>
...
So at this point, I'm completely lost. Any insights would be greatly appreciated. If there's any other info I can provide, please let me know.
While possible the normal solution would be to assume it is "just another data source" and use the Web reference on your Server side instead to provide data (and to provide insulation against future changes).
Silverlight App <=> Silverlight Web Services <= External/Legacy Web Service
Keep your Silverlight app slim and let the server do any heavy lifting for you.

read list items from sharepoint 2010 server to silverlight web application (cross-domain)

on one server i have www with silverlight web application. In a diffrent place in the world is the secound server with sharepoint 2010 fondation. While client connects to www server, the silverloght web application goes to him, and then trying to read list elements from sharepoint. On client desktop comes Windows - login window, after client provide username and the password, application can read the list items.
Question:
how to login IN THIS CASE from silverlight application without user prompt.
part of my code (reads only list infromation):
SilverlightApplication2.listsWebService.ListsSoapClient lws = new SilverlightApplication2.listsWebService.ListsSoapClient();
public MainPage()
{
InitializeComponent();
lws.GetListCompleted += new EventHandler<listsWebService.GetListCompletedEventArgs>(lws_GetListCompleted);
lws.GetListAsync("PagesContent");
}
void lws_GetListCompleted(object sender, listsWebService.GetListCompletedEventArgs e)
{
deltaValue.Text = e.Result.Value;
}
It can be very confusing when solving Silverlight auth in Sharepoint. I know this is possible when using Forms authentication, through web service called autentication.asmx.
With Windows authentication, I always used current logged user (which is SL default behavior).
I don't know if that can be changed from inside SL..
Here is one article that may help...
Sorry for such answer... :)

CommunicationException when invoking Web Service from Silverlight 4

(Updated)
I've built a simple Silverlight 4 Bing Maps app using the VS2010 template.
Within the same solution I've got an ASP.NET project with a simple Web Service: ContentService.asmx.
I'm running both from my local machine for now.
I can invoke the Web Service from within an ASP.NET page with no problems.
However, try as I might, I can't get Silverlight to talk to it.
I try to invoke the Web Service from Silverlight as follows:
public BingMapAppPanel()
{
InitializeComponent();
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
EndpointAddress endPoint = new EndpointAddress("http://localhost:49501/ContentService.asmx");
ContentServiceSoapClient contentService = new ContentServiceSoapClient(binding, endPoint);
contentService.GetAllCategoriesCompleted += new EventHandler<GetAllCategoriesCompletedEventArgs>(contentService_GetAllCategoriesCompleted);
contentService.GetAllCategoriesAsync();
}
void contentService_GetAllCategoriesCompleted(object sender, GetAllCategoriesCompletedEventArgs e)
{
MessageBox.Show(e.Result.Count.ToString());
}
It should output the count of the returned List object but instead it throws the following exception:
Bing Maps has encountered an exception. Please press CTRL+C to copy the error message text.
ErrorSource: Unhandled Exception.
ErrorType: System.Reflection.TargetInvocationException
ErrorMessage: An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
ErrorCallStack:
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at BingMapApp.Content.GetAllCategoriesCompletedEventArgs.get_Result()
at BingMapApp.BingMapAppPanel.contentService_GetAllCategoriesCompleted(Object sender, GetAllCategoriesCompletedEventArgs e)
at BingMapApp.Content.ContentServiceSoapClient.OnGetAllCategoriesCompleted(Object state)
InnerType: System.ServiceModel.CommunicationException
InnerMessage:
InnerCallStack:
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at BingMapApp.Content.ContentServiceSoapClient.ContentServiceSoapClientChannel.EndGetAllCategories(IAsyncResult result)
at BingMapApp.Content.ContentServiceSoapClient.BingMapApp.Content.ContentServiceSoap.EndGetAllCategories(IAsyncResult result)
at BingMapApp.Content.ContentServiceSoapClient.EndGetAllCategories(IAsyncResult result)
at BingMapApp.Content.ContentServiceSoapClient.OnEndGetAllCategories(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
I've tried various crossdomain.xml and clientaccesspolicy.xml files, nothing works.
Any suggestions much appreciated - thanks.
Update
I changed the endpoint address to 127.0.0.1 instead of localhost and it worked!
EndpointAddress endPoint = new EndpointAddress("http://127.0.0.1:49501/ContentService.asmx");
Anyone know why?
I'm guessing you've added another Web project to your solution to host this WCF service? If so, it most likely is a cross domain issue, where the Silverlight application is attempting to communicate with a service on another domain than the one from which it originated (even though it's only the port number that differs. If possible, host the WCF service in the project that was created when you created the Silverlight application, and this will likely solve your problem. If you're still having trouble (or this wasn't the case), try using Fiddler to see what's happening behind the scenes. To get Fiddler to pick up the traffic however (it ignores localhost traffic), replace references to localhost in your URIs with ipv4.fiddler.
Hope this helps...
Chris Anderson
Note: I didn't see your edit before I posted this. That's a weird one!

Silverlight 4 webclient authentication - anyone have this working yet?

So one of the best parts about the new Silverlight 4 beta is that they finally implemented the big missing feature of the networking stack - Network Credentials!
In the below I have a working request setup, but for some reason I get a "security error" when the request comes back - is this because twitter.com rejected my api call or something that I'm missing in code?
It might be good to point out that when I watch this code execute via fiddler it shows that the xml file for cross domain is pulled down successfully, but that is the last request shown by fiddler ...
public void RequestTimelineFromTwitterAPI()
{
WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);
WebClient myService = new WebClient();
myService.AllowReadStreamBuffering = true;
myService.UseDefaultCredentials = false;
myService.Credentials = new NetworkCredential("username", "password");
myService.UseDefaultCredentials = false;
myService.OpenReadCompleted += new OpenReadCompletedEventHandler(TimelineRequestCompleted);
myService.OpenReadAsync(new Uri("https://twitter.com/statuses/friends_timeline.xml"));
}
public void TimelineRequestCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
{
//anytime I query for e.Result I get a security error
}
I found 2 issues that caused this request to throw the security exception
1) - In this video by Tim Heuer it turns out my VS2010 w/ Silverlight 4 toolkit installation didn't match the final build so I'm missing the option that shows up in the "out of browser settings" dialog that provides the checkbox for "Require elevated trust when running outside the browser".
In the video listed above Tim checks this so the Silverlight app can talk to the twitter API
But because my application didn't have this option I had to manually edit the xml file so it looked like the below. You can find this xml under properties in the project folder or inside visual studio directly.
<OutOfBrowserSettings ShortName="TrustedNetworkApp Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>TrustedNetworkApp Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="TrustedNetworkApp Application" Height="480" Width="640" />
</OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.SecuritySettings>
<SecuritySettings ElevatedPermissions="Required" />
</OutOfBrowserSettings.SecuritySettings>
<OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>
Notice the **security settings ElevatedPermissions="Required"
After you save this it's equivalent to checking this as Tim did in the video.
2) - as I was watching that video by Tim I noticed that you have to debug this outside of the browser to get it working. So install the app and run it outside the browser. This app now works.
I'll write a short blog post to summarize my experience with the networking stack under the beta and link to it for anyone interested.
Update
I finally wrote a blog post about my experience building an out of browser twitter client using Silverlight 4 if anyone is interested.

Silverlight app. displays "ConfigFileMissing" message when trying to use a web service

The silverlight class library throws System.InvalidOperationException exception with "ConfigFileMissing" message when trying to access a very simple SOAP web service.
As you can see there's only one line of code that initializes the client. This is the line where exception happens.
public void GetDataFromWebService()
{
ServiceReference.WebServiceSoapClient client = new ServiceReference.WebServiceSoapClient();
}
Any idea?
Check to make sure you have a ServiceReferences.ClientConfig file in the root directoy of your silverlight project.

Resources