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

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.

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.

Open Notepad from Silverlight 4 Business Application

I have a Silvleright Business Application, Silverlight_BussApp.
It has the Silverlight_BussApp project and the Silverlight_BussApp.Web project.
I need to open Notepad after populating it in the code behind on a button click event.
I cannot make this an out of browser application.
So since Silverlight does not allow me to do it, I created a WCF Service in the Silverlight_BussApp.Web project
and invoked it through a proxy in the Silverlight Project. This works fine.
The code in the WCF Service is:
public void openFileWithNotepad(string filename)
{
try
{
if (File.Exists(filename))
{
Process.Start("notepad.exe", filename);
}
else
{
MessageBox.Show(
"I was unable to locate the following file: " + filename,
"File Not Found");
}
}
catch (Exception e)
{
throw e;
}
}
Now I need to use this openFile functionality in more than one Silverlight Project.
So I created a "WCF service Project" and created a WCF Service, hosted it on IIS, and created a proxy in the Silverlight project. To my dismay, the file does not open and it keeps giving me the "File Not Found" Error.
Can somebody help me figure out how I can make this a reusable functionality for all my Silverlight projects?
Why is it when I use the same code in a WCF Service hosted on IIS it does not work while it works perfectly when hosted in the same solution of the Silverlight project?
For starters, the code in the Silverlight_BussApp.Web project is going to be executed on the server, while the code in the Silverlight_BussApp project is going to be executed on the client. During development, the client and the server are ostensibly the same machine -- when you click "Run" in Visual Studio, a development web server starts up on your machine and hosts your .Web project, while the Silverlight application runs in your browser.
When your application is deployed, the client (i.e., your browser) will most likely be on a different physical machine than the server (i.e., IIS). So, ignoring any other security restrictions that may be imposed by IIS (which is probably why you're getting a "File Not Found" error), the call to Process.Start would start Notepad on an entirely different machine than the one you're using.
Try using a SaveFileDialog to save whatever you want to the client's machine, then tell them to open the resulting file.

Silverlight trying to access local crossdomainpolicy.xml

I have a Silverlight app that I developed locally, and I'm trying to run it on a Windows 2008 R2 server that I personally setup. Everything smooth and dandy, except that when I try to auth on the app, it tries to look locally for
http://localhost/crossdomainpolicy.xml
http://localhost/clientaccesspolicy.xml
It also throws a nasty error :
Uncaught Error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at SomeService.MVServiceReference.CheckUserCompletedEventArgs.get_Result()
at SomeService.Pagini.Autentificare.AuthForm.webServiceSoapClient_CheckUserCompleted(Object sender, CheckUserCompletedEventArgs e)
at SomeService.MVServiceReference.MVWebServiceSoapClient.OnCheckUserCompleted(Object state)
If your XAP file is on http://localhost/somewhere/somefile.xap it shouldn't look for a clientaccesspolicy. Are you using the ASP.NET dev. server to host the Silverlight app while you are using IIS for a WCF service that is called by the silverlight app?
Silverlight's inability to present exception details is well known. It is due to the fact that all communication from a Silverlight component to a service utilizes the hosting browser and when there is an error returned with a http error code, the browser only returns the error code and not the message containing the exception details to silverlight.
Activate WCF trace logging on the server side and look in the svc-log to get the real exception message.
For crossdomain purposes, http://localhost/ , http://localhost:1234/ and http://localhost:4321/ are all different domains.

Silverlight and Windows Workflow Foundation

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.

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.

Resources