当EndpointAddress指向别名

时间:2018-09-21 18:46:03

标签: wcf endpoint

我正在尝试使用别名而不是真实的URL调用WCF服务。

当我的EndpointAddress直接指向.svc时,该服务正常工作。

public class WCFClientProxyFactory
{
    private static readonly EndpointAddress _Endpoint = new EndpointAddress("http://example.com/MyDataService.svc");

    public static MyDataServiceClient CreateWCFClientProxy()
    {
        MyDataServiceClient client;
        BasicHttpBinding binding = CreateBasicHttp();
        client = new MyDataServiceClient(binding, _Endpoint);
        return client;
    }

    private static BasicHttpBinding CreateBasicHttp()
    {
        BasicHttpBinding binding = new BasicHttpBinding
        {
            Name = "basicHttpBinding",
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647
        };
        TimeSpan timeout = new TimeSpan(0, 0, 30);
        binding.SendTimeout = timeout;
        binding.OpenTimeout = timeout;
        binding.ReceiveTimeout = timeout;
        return binding;
    }
}

我们让第三方托管服务商设置了一个指向同一站点的别名。我可以使用该别名浏览到.svc(即,我在顶部看到“这是Windows©Communication Foundation服务。”消息)。但是,当我尝试使用指向别名而不是实际站点URL的EndpointAddress进行相同的调用时,我的客户端应用程序挂起:

public class WCFClientProxyFactory
{
    private static readonly EndpointAddress _Endpoint = new EndpointAddress("http://alias.example.com/MyDataService.svc");

    public static MyDataServiceClient CreateWCFClientProxy()
    {
        MyDataServiceClient client;
        BasicHttpBinding binding = CreateBasicHttp();
        client = new MyDataServiceClient(binding, _Endpoint);
        return client;
    }

    private static BasicHttpBinding CreateBasicHttp()
    {
        BasicHttpBinding binding = new BasicHttpBinding
        {
            Name = "basicHttpBinding",
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647
        };
        TimeSpan timeout = new TimeSpan(0, 0, 30);
        binding.SendTimeout = timeout;
        binding.OpenTimeout = timeout;
        binding.ReceiveTimeout = timeout;
        return binding;
    }
}

它没有超时,所以这告诉我该请求很可能成为服务对象。但它永远不会回来。我已经让它坐在那里10分钟了,没有任何反应。

以下是客户端调用该服务的语法:

        MyDataServiceClient client;
        client = WCFClientProxyFactory.CreateWCFClientProxy();
        client.AuthenticateCompleted += (sender, e) =>
        {
           .....
        }
        client.AuthenticateAsync(userID, password);

0 个答案:

没有答案