Wednesday, October 2, 2013

Passing value of an array to WCF Test Client

This blog might look very simple but at least useful for first time users of  WCF test client .

The Question here is how to pass the value of an array to WCF Test Client

Your Service Method method looks like the below ; you may notice that the method accepts a List<String> Values as input parameter .

 

image

Now Lets Run the WCF Project and see how it look like in the Test Client

image

Your Test Lists the method and its Parameters as shown in the above screen shot

 

image

 

Now Lets see how we can Pass the Values to the array . In Normal scenario you may not notice how we can enter the values . But you may notice one thing that the length of the array is Zero (0) .

Now change the length of the array to 2  and see what is the change happening

 

image

Now you can see the array value section is modified with an expander an you are provided with two options to enter the values

 

image

 

Enter the values in the Value field and test your service .

 

Happy Coding :)

Monday, January 28, 2013

Resolving Same Origin Policy restrictions ( Cross Domain Issues) using JQuery Ajax Calls and JSONP

 

Being a  web developer , you must be at least one time used JQuery Ajax requests from your client end . And the growing popularity of HTML 5 demands more such calls . And the main headache occurs when you want to access some thing from server , which may be hosted in a different domain .

The commonly suggested solution to this problem is to use  “JSONP” as data type in your Ajax request . Even though the same thing is repeated in all forums , but none clearly mentions what is JSONP and how you can implement it for cross domain – “GET” requests .

JSONP

JSONP is an addition JSON request ( JSON with Padding )  , it wraps JSON in a function call.  For example, the following might be returned from the third-party server:

mycallback({"key" : "value"});

Code Snippet

In your regular JQuery Ajax Call , modify the “dataType “ Parameter to “jsonp”  and add a new parameter called “jsonpCallback” .  set the value to the call back function same as the one which you are going to specify in your server file. here in this example it is “mycallback”  . 

Your Script Would looking like the below

<script type="text/javascript">
var URL = "
http://MyServer/OL/version.txt";
$.ajax(URL, {
crossDomain: true,
dataType: "jsonp",
jsonpCallback: mycallback,
success: function (data, text, xhqr) {
alert(data.text);
},
error: function (xhqr) {
console.log("Error");
}
});
</script>

Now your client is ready to send and receive cross domain Ajax calls  .  Now we’ll have a look at your server side file from which you are returning some data to client side .

Now modify your server side file say for example “version.txt”   as shown below .

mycallback({"text" : "Hello World This Text is from cross domain server "})

The above statement is a method which wraps your Json Data .

Happy Coding Smile

 

Wednesday, October 12, 2011

HTTP could not register URL http://+:8000/. Your process does not have access rights to this namespace

 

Last week we had this issue when working with an Outlook Addin. After a lot of trial and errors , finally we got this solution .

Run Command Prompt as Administrator and execute the  below command

netsh http add urlacl http://+:8000/ user=domain\username.

Happy Coding Smile