I am hosting a silverlight 3.0 control on my Sharepoint 2010 page. I am using the built-in SilverlightWebPart web part, where I have provided the path for .xap file.
Its displaying properly, but when I try to access the System.Windows.Browser, its throwing an error. My code is:
public static string GetQueryString(string key)
{
try
{
var documentQueryString = (Dictionary<string, string>)System.Windows.Browser.HtmlPage.Document.QueryString;
if (documentQueryString.ContainsKey(key))
{
return documentQueryString[key].ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return string.Empty;
}
The error I am getting is: The DOM/scripting bridge is disabled. How do I enable this? I know if I host this in a ASP.NET page, I can add the param - <param name="enablehtmlaccess" value="true"/>. I have tried putting this webpart in a "content editor web part", and I have embedded the object tag to call the .xap file and its working totally fine. I need to make it work using the built-in Silverlight web part.
Related
I'm new to Appium and testing as a whole. I used Android driver to test an app in android.
I can handle all clicks and typing in the app. But the issue arises while using the OAuth service to log in the app.
I use the following Driver client. appium dotnet driver
The login service opens in a separate chrome browser. I have to type text in an input element inside the web page.
I use the following code. On debugging page resource only has the android elements of the chrome browser and nothing of the web content.
var appiumDriver = new AndroidDriver<AndroidElement>(driverUri, appiumOptions);
[Test()]
[Order(1)]
public async Task TestLogin()
{
try
{
appiumDriver.FindElementByAccessibilityId("Login").Click();
await Task.Delay(3000);
var source = appiumDriver.PageSource;
var element = appiumDriver.FindElementById("login-email");
}
catch (NoSuchElementException ex)
{
}
}
Can anyone suggest how to proceed with this problem? This also has to be done in iOS, I guess both can be handled the same way.. Thanks in advance.
The issue was not changing to web context for searching in web page. The test flow had to be
Perform action to open the web page from the app. (In my case clicking login button)
Wait till the web page appears. (This is important as the web context will be available only after the web page appears) For this, I used a FindElementByClassName for a unique control visible in the web page but not on the previous App page. There sure can be a better way.
Get available contexts and switch to web context.
I used FindByCssSelector for finding the element with id.
Changing to web context
public static void ChangeToWebContext()
{
if (driver.Context != "NATIVE_APP")
return;
var elements = driver.FindElementByClassName("android.widget.EditText");
var availableContext = driver.Contexts;
if (availableContext.Count >= 2)
{
driver.Context = availableContext[1];
return;
}
}
Usgae:
this.ChangeToWebContext();
driver.FindElementByCssSelector("#login-password");
I have written a WCF API. It runs (ran) just fine.
Now that I need to open it up to public access I tried to implement API Key verification following the example of Ron Jacobs and the accompanying video on endpoint.tv
This basically just uses a list of GUIDs stored in an xml file that represent the valid API keys. The authorization request key is passed via query string and validated in a custom ServiceAuthorizationManager like this:
protected override bool CheckAccessCore(OperationContext operationContext)
{
return IsValidAPIKey(operationContext);
}
public static bool IsValidAPIKey(OperationContext operationContext)
{
string key = TvinQuery.GetAPIKey(operationContext);
Guid apiKey;
// Convert the string into a Guid and validate it
if (Guid.TryParse(key, out apiKey) && TvinQuery.APIKeys.Contains(apiKey))
{
return true;
}
else
{
return false;
}
}
TvinQuery.APIKeysis a simple List<string> containing the valid guids from the xml file.
The solution compiles, but when I publish it on my server and try to access the service there, I get a FileNotFound exception for file or assembly "WCFWebHttp" or one of its dependencies.
The cause for this is very obviously this part in the service behavior node of web.config:
<serviceAuthorization serviceAuthorizationManagerType="WCFWebHttp.APIKeyAuthorization, WCFWebHttp" />
Unfortunately, neither a search through my assemblies nor through my file system nor an internet search nor a nuget package search came up with an assembly of that name.
Event viewer and enabled tracing did not reveal any further information either.
What is it? How can I solve this error? Is there anything wrong or missing with the example? It worked just fine in the video and that was a live presentation. :-?
As from this picture:
at https://blogs.msdn.microsoft.com/rjacobs/2010/06/14/how-to-do-api-key-verification-for-rest-services-in-net-4/
it looks like WCFWebHttp is an assembly implemented in the source code of the sample you've used (which I can't download right now to make sure because of server error).
Hello i have been creating a web browser for college. The problem that i have that is driving me insane is trying to get current web browser page i am ons text in the tab like if i am on Google i would like to say it in the tab.
i tried
private void addTextImageTab()
{
try
{
mainBrowserTC.SelectedTab.Text = getCurrentWB().Document.Url.ToString();
}
catch
{
MessageBox.Show("Error");
}
}
and my getCurrentWB() method is
private WebBrowser getCurrentWB()
{
return (WebBrowser)mainBrowserTC.SelectedTab.Controls[0];
}
Every time i try to run it it crashes i tried every thing that i know and search the web the last few days and could find a solution please help.
After my previous question HERE, I found the solution (well, part of it).
Here's the code for Java part:
#WebService
public class MyWebService
{
#WebMethod
public String myMethod()
{
return "Hello World";
}
#WebMethod
public int Add(#WebParam(name="a") int a,
#WebParam(name="b") int b)
{
return a + b;
}
public static void main(String[] args)
{
String address = "http://127.0.0.1:8023/_WebServiceDemo";
Endpoint.publish(address, new MyWebService());
System.out.println("Listening: " + address);
}
}
And Here is the Silverlight part:
private void SearchResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MyWebServiceClient proxy = new MyWebServiceClient();
proxy.AddCompleted += proxy_AddCompleted;
proxy.AddAsync(2, 3);
}
void proxy_AddCompleted(object sender, AddCompletedEventArgs e)
{
txtSearch.Text = e.Result.ToString();
}
But when I run this, e.Result throws an exception.
What am I missing/ How should I solve it?
Note that this code runs perfectly in C# Console application (when it's not async). But when I run the async code, it doesn't work.
Thanks in advance.
I guess you are getting a System.ServiceModel.CommunicationException when trying to access the Java Webservice from Silverlight.
There is nothing basically wrong with your code, and it should also work with async calls in C# Console App.
The main problem is that Silverlight (as a browser plugin) enforces some security restrictions that prevent a Silverlight Application to talk to another server than the one loaded from (defined by server name and port) without further configuration. This behaviour can be configured as described here (also search for "silverlight cross-domain calls" or "silverlight cross domain policy").
This restrictions (normally) do not apply to desktop or console applications so they'll work fine with the same web service.
To make your code work you need to host the Silverlight Application inside the same "project" / website than your webservice (so I suppose, the self-hosting webservice won't work and you need to switch to Java web project where the webservice is to be hosted). As the Silverlight Application basically consists of an enclosing HTML file plus the referenced binaries, you can host it on any server, e.g. Apache Tomcat.
Hope this helps.
I want to be able to use server2 if server1 fails, so I have two web references but this leads to an "Ambiguous reference" error because it is the same service on both servers.
This is the C# code:
using App.org.weccrc.www; // Main Server
using App.org.weccrc.www2; // Backup Server
Is there a way to check if the service is available on server1 before the "using" statement"?
can this be a conditional statement?
Or there is another approach to solve this issue.
Thanks in advance
Raúl
I would do something like this
public R CallWebservice<T,R>(T service, IEnumerable<string> urls, Func<T,R> serviceCall)
where T : SoapHttpClientProtocol, IDisposable
{
foreach (var url in urls)
{
try {
service.Url = url;
return serviceCall(service);
} catch (Exception ex) {
// Log Error
continue;
} finally {
service.Dispose();
}
}
// throw exception here which means that all url's failed
}
and you could call it doing something like this
Employee[] employees = CallWebService(
new DownloadService(),
new string[] { "http://site1/service.asmx","http://site2/service.asmx" },
service => service.DownloadEmployees()
);
this would loop through each URL specified and call the webservice. if it fails, then it just attempts to do the next URL until it executes successfully.
On your web reference, set the URL Behavior to Dynamic. The generated code for the web reference will now have a configuration setting that controls the location. When you detect that the primary service has failed, you can set the Url property to the fallback location.
How you detect that the primary service has failed will of course depend on the service you're consuming.