Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
//string uri = "http://localhost:58993/ServiceManager.svc/GetData" ;
            //uri += sz.SerializeToJsonString(f) ;
            string uri = "http://xyz.com:4568/ServiceManager.svc/GetData";
            byte[] encData_byte = new byte[sz.SerializeToJsonString(lFilter).Length];
            encData_byte = Encoding.UTF8.GetBytes(sz.SerializeToJsonString(lFilter));
            string encodedData = Convert.ToBase64String(encData_byte);
            uri += "/?lfilter=" + encodedData ;
            WebClient dataClient = new WebClient();
            dataClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(dataClient_DownloadStringCompleted);
            dataClient.DownloadStringAsync(new Uri(uri));


In the above code, when i am using http://localhost:58993.... it is working fine,
but when i host the same service as separate as http://xyz.com:4568.. it is not working.

Please help me. Thanks in advance
Posted

1) Does xyz.com resolve correctly to the hosting server?
2) Is port 4568 open on the server hosting the service?

If you get an answer to these two questions then you should be much further along. If you still can't hit the service correctly, then post any errors you are receiving and I can expand the answer based on that information.
 
Share this answer
 
You should use cross-domain policy files when accessing third party web services. There are some ways to develop it; I explain a way that it can solve your problem.
Note1: The request http://localhost:58993 is different with http://xyz.com:4568 in security context.
Step 1: Create IPolicyRetriever interface

[ServiceContract]
public interface IPolicyRetriever
{
    [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
    Stream GetSilverlightPolicy();
    [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
    Stream GetFlashPolicy();
}


Step2 : Implement IPolicyRetriever interface in your service

public class Service1 : IService1, IPolicyRetriever
{
    #region [ IPolicyRetriever Members ]
    Stream StringToStream(string result)
    {
        WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
        return new MemoryStream(Encoding.UTF8.GetBytes(result));
    }
    public Stream GetSilverlightPolicy()
    {
        string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
                            <access-policy>
                                <cross-domain-access>
                                    <policy>
                                        <allow-from http-request-headers=""*"">
                                            <domain uri=""*""/>
                                        </allow-from>
                                        <grant-to>
                                            <resource path=""/"" include-subpaths=""true""/>
                                        </grant-to>
                                    </policy>
                                </cross-domain-access>
                            </access-policy>";
        return StringToStream(result);
    }
    public Stream GetFlashPolicy()
    {
        string result = @"<?xml version=""1.0""?>
                        <!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
                        <cross-domain-policy>
                            <allow-access-from domain=""*"" />
                        </cross-domain-policy>";
        return StringToStream(result);
    }
    #endregion
}



Note2: Tim Heuer describes another way in this video :
http://www.silverlight.net/learn/videos/all/how-to-use-cross-domain-policy-files-with-silverlight/
 
Share this answer
 
v2

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