REST WCF Web客户端服务中的问题 [英] Problem in REST WCF webclient service

查看:130
本文介绍了REST WCF Web客户端服务中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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));



在上面的代码中,当我使用http://localhost:58993 ....时,它工作正常,
但是当我托管与http://xyz.com:4568 ..相同的服务时,它却无法正常工作.

请帮我.在此先感谢



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

推荐答案

1)xyz.com是否可以正确解析为托管服务器?
2)托管服务的服务器上的端口4568是否打开?

如果您回答了这两个问题,那么您应该走得更远.如果仍然无法正常使用该服务,请发布您收到的任何错误,然后我可以根据该信息扩展答案.
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.


您应在以下情况下使用跨域策略文件:访问第三方Web服务.有一些方法可以开发它.我将说明一种可以解决您的问题的方法.
Note1:在安全上下文中,请求 http://localhost:58993 http://xyz.com:4568 不同. /> 步骤1:创建IPolicyRetriever接口

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();
}



第2步:在您的服务中实现IPolicyRetriever接口



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在本视频中介绍了另一种方式:
http://www.silverlight.net /learn/videos/all/how-to-to-use-cross-domain-policy-files-with-silverlight/




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/


这篇关于REST WCF Web客户端服务中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆