Click here to Skip to main content
15,301,414 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all,

I am facing a problem on a windows web service. Although I havent made any changes on my code, lately I ve been receiving this error. What I am trying to do is connecting to a web service and make a call and get a responce. So if i can get a responce I have a XML written to a string. But now it fails and goes directly to my catch statement.

The weird thing is, I can access the XML when I put the URL to the browser.

In addition to that;
in order to make a call I am using a IDictionary.
the code goes like that;

XML
IDictionary<string, string> r3 = new Dictionary<string, String>();
            r3["Service"] = "ECommerceService";
            r3["Operation"] = "ItemLookup";
            r3["ItemId"] = asin;
            r3["MerchantId"] = "Featured";
            r3["ResponseGroup"] = "Medium,OfferFull,Reviews";


MIDL
string urlReq = HttpUtility.UrlDecode(r3.Values.ToString());
            requestUrl = helper.Sign(urlReq);

This doesnt work because on the request url it apeears as;

- http://onca/xml?AccessKeyId=0JB3Q7C8ZC0YD8WE7BG2&System.Collections.Generic.Dictionary`2[System.String,System.String]=&Timestamp=2011-02-14T19:00:13Z

On the link here "
C++
System.Collections.Generic.Dictionary`2[System.String,System.String]=&

" there should be values.

The correct must be ;

-http://onca/xml?AccessKeyId=0JB3Q7C8ZC0YD8WE7BG2&ItemId=B000E2EZDM&MerchantId=Featured&Operation=ItemLookup&ResponseGroup=Medium%2COfferFull%2CReviews&Service=AWSECommerceService&Timestamp=2011-02-14T17%3A14%3A25Z&

So instead of "
C++
System.Collections.Generic.Dictionary`2[System.String,System.String]=&

" i need this there"
C++
&ItemId=B000E2EZDM&MerchantId=Featured&Operation=ItemLookup&ResponseGroup=Medium%2COfferFull%2CReviews&Service=AWSECommerceService&

"

In order to get that how can I get it from IDictionary like that can someone help? I am open to new ideas as well?

What I am thinking but cant figure out yet; I tried

C#
string urlReq = "";
            foreach (string url in r3.Values)
            {
                urlReq = r3[url] + "&";
            }
            urlReq = urlReq.Substring(0, urlReq.Length - 1);
            urlReq = HttpUtility.UrlDecode(urlReq);


But this foreach is faulty. what is the proper way for it? I hope I am clear.

Thanks.
Posted

1 solution

Try this:

C#
IDictionary<string, string> r3 = new Dictionary<string, string>();
r3["Service"] = "ECommerceService";
r3["Operation"] = "ItemLookup";
r3["ItemId"] = "asin";
r3["MerchantId"] = "Featured";
r3["ResponseGroup"] = "Medium,OfferFull,Reviews";

var urlString = String.Join(string.Empty, r3.Select(it => String.Format("&{0}={1}", it.Key, it.Value)));


urlString will now be: &Service=ECommerceService&Operation=ItemLookup&ItemId=asin&MerchantId=Featured&ResponseGroup=Medium,OfferFull,Reviews
   
v3
Comments
Orcun Iyigun 14-Feb-11 16:11pm
   
well I am having an error as;
Error 2 Argument '2': cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'.

How can I fix this?
Nish Nishant 14-Feb-11 16:13pm
   
Okay, what version of .NET are you on? The overload I used is .NET 4/Silverlight only.
Nish Nishant 14-Feb-11 16:14pm
   
Try this:

var urlString = String.Join(string.Empty, r3.Select(it => String.Format("&{0}={1}", it.Key, it.Value)).ToArray());

That should work with .NET 3.5 which is what I think you are on.
Orcun Iyigun 14-Feb-11 16:25pm
   
Thanks.
Nish Nishant 14-Feb-11 16:26pm
   
I hope that worked.
Manfred Rudolf Bihy 14-Feb-11 16:29pm
   
Good answer and follow up! 5+
Nish Nishant 14-Feb-11 16:33pm
   
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900