Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified
Accepted Solution

WCF Service and Blackberry Widget not working. See where I'm going wrong?

I am creating a BB widget with Visual Studio 2008 and I've created a WCF Service, that is hosted in Windows Azure.

 

Here is one of the methods in the WCF Service:

 

 public string ClockIn(string emailAddress)
        {
            try
            {
                using (var dc = new TEI_DataContext(_MyDc))
                {
                    SecurityLogin sl = dc.SecurityLogins.SingleOrDefault(s => s.EmailAddress == emailAddress);
                    var tc = new TimeClock { ClockIn = DateTime.Now, UserName = sl.UserName };
                    dc.TimeClocks.InsertOnSubmit(tc);
                    dc.SubmitChanges();
                    return "You're Clocked In!";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }

 

I've tested it with a Console Application like this, and it works GREAT!

 

var client = new TEIServiceReference.Service1Client();
string result = client.ClockIn("sdgfsdgfds@gmail.com");
Console.WriteLine(result);
Console.Read();

 Here is the public WCF Service address: http://a1e17152bcf647aaa300ccb5a8a2a2c5.cloudapp.net/Service1.svc

 

Here is my HTML widget code:

 

<script type="text/javascript" src="scripts/actions.js"></script>
<html>
<head>
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<title>TEI Time Clock</title>
</head>
<body>
<input type="button" value="Clock In" onclick="ClockIn();" />
</body>
</html>

 

 

And here is my JavaScript code:

 

var xmlHttp = new XMLHttpRequest();

function ClockIn()
{
var url = "http://a1e17152bcf647aaa300ccb5a8a2a2c5.cloudapp.net/Service1.svc/ClockIn/geekbrenhatch@gmail.com";
xmlHttp.open('GET', url, true);
xmlHttp.onreadystatechange = callbackFunctionClockIn;
xmlHttp.send(null);
}

function callbackFunctionClockIn()
{

if (xmlHttp.readyState == 4)
{
var result = xmlHttp.responseText;
//result = result.getElementsByTagName("string")0].childNodes[0].nodeValue;
alert(result);
}
}

 

 

When I run the widget, a BLANK popup appears and it does NOT clock me in. Can anyone see what I'm missing? 

 

Thanks SO much for your help and time!

 

Brenda

 

 

 

 

Developer
Posts: 164
Registered: ‎08-26-2010
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

have not try it yet, but from your codes, it seems:

 

var result = xmlHttp.responseText;

should be like this:

 

var result = xmlHttp.responseXML;

 

 

 

New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

When I change it to xmlHttp.responseXML, it returns null. Somehow I must not be hitting the WCF Service correctly???

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Have you white listed your target domain in the config.xml file?  Any external domain that you are looking to access needs to be declared in the config.xml file using the <access> element to allow for cross origin AJAX requests.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Yep, I've done that already. See anything else I could be missing? Am I scripting the call to the service correctly?

 

Thanks for your time!

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Have you setup the web service to allow GET/POST access?  I'm personally not that familiar with the Azure infrastructure... but I know that an ASP.NET web service requires special web.config settings.

 

 http://supportforums.blackberry.com/t5/Web-Development/How-quot-I-quot-would-call-a-web-service-from...

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Good thinking, once again, but yes, I've added that to my web.config file. I've looked over that post many times and can't figure out where I'm going wrong.

 

 <webServices>
    <protocols>
      <add name="HttpSoap"/>
      <add name="HttpGet"/>
    </protocols>
  </webServices>

 

The odd thing is that I can run it from a Console application, but not from my Blackberry Sample Widget.

 

Are you for hire? 

New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Any other ideas out there? I really need some help on this one (just like every programmer does lol).

 

Thanks for your time!

New Contributor
Posts: 2
Registered: ‎03-23-2011
My Device: Torch
My Carrier: AT&T

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

Hi,

This is probably too late but...

I recently did battle with a .net web service and a null xmlHttp.responseXML.

The problem was an error in the url.

I'm not positive but shouldn't there be a ? before the GET query string, between the web method and the parameter (email address)?

 

 

var url = "http://a1e17152bcf647aaa300ccb5a8a2a2c5.cloudapp.net/Service1.svc/ClockIn?geekbrenhatch@gmail.com";
New Contributor
Posts: 8
Registered: ‎03-08-2011
My Device: Not Specified

Re: WCF Service and Blackberry Widget not working. See where I'm going wrong?

The ? didn't help either. Bummer!

 

I just hired a Blackberry App developer, and he figured it out in Java. 

 

Thanks for trying to help out though!