9

我有一个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 一起工作,只使用代码?

4

3 回答 3

6

我相信您的问题出在您的配置文件中,请尝试添加到绑定标签中。关于这个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" />

于 2015-05-21T06:51:23.030 回答
3

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

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

于 2015-05-26T15:48:47.907 回答
2

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

我设法使用以下 SSL 中性客户端实现了所需的功能:

公共类 SoapServiceClient : Soap12ServiceClient
{
    公共 SoapServiceClient(string uri) : base(uri)
    {
        if (uri.StartsWithIgnoreCase("https://"))
        {
            var binding = (WSHttpBinding)base.Binding;
            binding.Security.Mode = SecurityMode.Transport;
        }
    }
}
于 2015-06-16T07:06:29.117 回答