CommunicationException when invoking Web Service from Silverlight 4 - silverlight

(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!

Related

Hosting Company under cyber attack!! Can I fix this myself or do I wait for the hosting company?

Our hosting company MijnHostingPartner.nl got hit badly by a cyber attack and most of their client's website have been down for weeks. I am a complete noob in coding, just working my way around it by using DNN to build a website. I've set up all the MSSQL DB's correctly and it's running smoothly for over a year now.
Since it's used daily by a small community of ten pin league bowlers - all results and news are displayed here - I'm getting quite the amount of complaints since it's down!
This is the error I get on both top-level as sub-level domains:
Server Error in '/' Application.
No http handler was found for request type 'GET'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: No http handler was found for request type 'GET'
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): No http handler was found for request type 'GET']
System.Web.HttpApplication.MapIntegratedHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig, Boolean convertNativeStaticFileModule) +748
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +589
[HttpException (0x80004005): Error executing child request for ~/ErrorPage.aspx.]
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +1295
System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) +72
System.Web.HttpServerUtility.Transfer(String path) +45
DotNetNuke.Common.Initialize.CheckVersion(HttpApplication app) +845
DotNetNuke.Common.Initialize.InitializeApp(HttpApplication app, Boolean& initialized) +154
DotNetNuke.Common.Initialize.Init(HttpApplication app) +157
DotNetNuke.HttpModules.RequestFilter.RequestFilterModule.FilterRequest(Object sender, EventArgs e) +258
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +139
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +88
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0
Does anyone have a clue what I'm talking about? 'Cause I sure don't. Please, if you explain it to me, explain in a way your dog would understand, if that's even possible.
Many thanks,
Robbe
If you are using a third-party hosting solution I would guess that you don't have the ability to change the values referenced in the comments section.
This error appears to be a very low-level issue with the server not being configured for ASP.NET hosting. (The underlying technology used by DNN.)
I'm not confident that you will have the ability to fix this without them. However, you have a few options.
Get the information on this error to the hosting provider. The key will be to determine if ANY services work A great check is to see if you can get the DNN Keep Alive to work. You can get to that via http://yoursite.com/keepalive.aspx
Extract a copy of the site files & database and move to another host. This is typically an easy option, but I would caution you that it would be prudent to have the site scanned for any potential malicious impacts PRIOR to moving to a new hosting provider unless you know for sure what the impact was to your hosting provider.
This is never a good situation, but one that you should be able to get past. If needed, this could be a time to reach out to someone that knows this stuff well, as there are a lot of little risks associated with a potentially compromised solution.

Silverlight application denied access to domain service in Internet Explorer 10

I am seeing a strange problem where my Silverlight application is failing to load due to an "Load operation failed for query.." and the reason is "Denied Access at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodPermissions"
If I browse to exactly the same page using IE 9 the request goes through and the silverlight application loads! This is happening on more than one server and their IIS and SQL Server have been configured the same as all other systems we set up.
With custom errors turned off I see the following stacktrace in Fiddler -
Denied Access#Detail#DomainServiceFaultDomainServices i)http://www.w3.org/2001/XMLSchema-instance# ErrorCode��#ErrorMessage�
Denied Access#IsDomainException�#
StackTrace�r at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodPermissions(DomainOperationEntry domainOperationEntry, Object entity)
at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodCall(DomainOperationEntry domainOperationEntry, Object[] parameters, List1 validationResults)
at System.ServiceModel.DomainServices.Server.DomainService.Query(QueryDescription queryDescription, IEnumerable1& validationErrors, Int32& totalCount)
at System.ServiceModel.DomainServices.Hosting.QueryProcessor.Process[TEntity](DomainService domainService, DomainOperationEntry queryOperation, Object[] parameters, ServiceQuery serviceQuery, IEnumerable1& validationErrors, Int32& totalCount)
at System.ServiceModel.DomainServices.Hosting.QueryOperationBehavior1.QueryOperationInvoker.InvokeCore(Object instance, Object[] inputs, Object[]& outputs)
The site is in my trusted sites.
When I attach to the silverlight application and debug the authentication process it seems to go through fine and the user is validated. But then when it actually tries to run the queries against the service subsequent to this they fail with access denied!
I'm lost as to why this would be any different in IE 10, any ideas would be appreciated! Thanks.
Not 100% proved this yet, but appears the hotfix suggested in this post - IE10 User-Agent causes ASP.Net to not send back Set-Cookie (IE10 not setting cookies) fixes the issue.
It seems there was a problem with IIS not handling IE10 cookies properly and so the authentication cookie was being set initially then subsequently ignored.
I'm guessing our machine was out of date, windows update-wise, as I presume this fix must have been distributed by now. But have yet to confirm.

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.

WebClient fails with remote server "NotFound"

I'm building a wp7 app. I'm using WebClient to grab data from a server. In the past, it's been working, although all of a sudden it's failing.
static void downloadData(string uri, Action<object, DownloadStringCompletedEventArgs> onComplete)
{
Debug.WriteLine("Downloading: " + uri);
WebClient data = new WebClient();
data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(onComplete);
data.DownloadStringAsync(new Uri(uri));
}
static void data_SectionDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
// throws NotFound
throw e.Error;
}
// ...
}
When I go to the URI in question in my browser, it works fine.
The exception:
"The remote server returned an error: NotFound." {System.Net.WebException}
What am I doing wrong here?
Update: I restarted the emulator, and now it works fine. Weird. Maybe it's an issue in the emulator? Hopefully I won't be able to reproduce it on the actual device.
NotFound is a generic error that basically means 'Error'. There is a real exception behind it that you need to dig to find. The easiest method I have found is Intellitrace which allows you to view every exception that ever happened on your web server. If you look just before your NotFound, you will find the real exception that backs it.
If Intellitrace is not an option, add more/better logging on your server and client. Google has many tips, a good example of deeper debugging:
http://www.mostlydevelopers.com/blog/post/2009/01/14/debugging-tips-ndash3b-the-remote-server-returned-an-error-notfound.aspx
I had similar experience with the emulator. I often open Internet Explorer and browse a site before I test any application that uses the network. Also, it is best not to change the IP address of the machine running the emulator, DHCP or manually. Lastly, I would suggest you handle any error scenarios with an error message displayed in a MessageBox.
HTH, indyfromoz
I get this occassionaly too. Even on real devices. A retry usually fixes it though.
Unfortunately this is one of the issues you need to be aware of and write code to cater for when working in an occassionally connected environment.

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.

Resources