ServiceStack Soap 1.2 HTTPS客户端

时间:2015-05-16 14:00:06

标签: c# soap https servicestack soap1.2

我有一个基于ServiceStack的Soap客户端,可以正常运行HTTP,但是当我尝试使用HTTPS时,它会给我这个错误

ServiceStack.WebServiceException: The provided URI scheme 'https' is invalid; ex
pected 'http'.
Parameter name: via ---> System.ArgumentException: The provided URI scheme 'http
s' is invalid; expected 'http'.
Parameter name: via
   at System.ServiceModel.Channels.HttpChannelFactory`1.ValidateCreateChannelPar
ameters(EndpointAddress remoteAddress, Uri via)
   at System.ServiceModel.Channels.HttpChannelFactory`1.OnCreateChannelCore(Endp
ointAddress remoteAddress, Uri via)
   at System.ServiceModel.Channels.ChannelFactoryBase`1.InternalCreateChannel(En
dpointAddress address, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOv
erRequest.CreateInnerChannelBinder(EndpointAddress to, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(En
dpointAddress address, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(Type chan
nelType, EndpointAddress address, Uri via)
   at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address
, Uri via)
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at ServiceStack.WcfServiceClient.Send(Message message)
   at ServiceStack.WcfServiceClient.Send[T](Object request)
   --- End of inner exception stack trace ---
   at ServiceStack.WcfServiceClient.Send[T](Object request)
   at ElectronicServiceInterface.ESIClient.Login()

我使用的是自签名证书,但我可以使用curl成功调用我的Soap服务。这对我来说表明问题出在客户端。

我的代码与

一致
using (var client = new Soap12ServiceClient(Uri))
{
    var request = new MyRequestObject { Username = Username, Password = Password };
    var response = client.Send<MyResponseObject>(request);
}

以上显示了示例请求/响应DTO类的用法。

如果不使用配置文件,只需使用代码,我需要做些什么才能使用HTTPS?

3 个答案:

答案 0 :(得分:5)

我相信你的问题在你的配置文件中,  尝试添加到绑定标记。  关于这个ServiceStack.IntegrationTests你应该有

<bindings>
            <basicHttpBinding>
                <binding name="Endpoint_BasicHttpBinding" />
            </basicHttpBinding>
            <wsHttpBinding>
                <binding name="Endpoint_WsHttpBinding">
                    <security mode="None">
                        <transport clientCredentialType="None" />
                        <message establishSecurityContext="false" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>

但在此测试中,它仅配置为使用HTTP而非HTTPS,因此您只需将<transport clientCredentialType="None" />更改为<transport clientCredentialType="transport" />

答案 1 :(得分:3)

您需要有2个单独的基址,一个用于HTTP,另一个用于HTTPS。

您可以在配置文件或执行托管的代码中定义它。

答案 2 :(得分:2)

配置文件的问题在于它并不总是直截了当的,有时候是不切实际的。在此ServiceStack之上,推广无配置编码模型。

我设法通过以下SSL中立客户端实现所需的功能:

public class SoapServiceClient : Soap12ServiceClient
{
    public SoapServiceClient(string uri) : base(uri)
    {
        if (uri.StartsWithIgnoreCase("https://"))
        {
            var binding = (WSHttpBinding)base.Binding;
            binding.Security.Mode = SecurityMode.Transport;
        }
    }
}