ServiceStack Soap 1.2 HTTPS Client

本文关键字:HTTPS Client Soap ServiceStack | 更新日期: 2023-09-27 17:49:27

我有一个基于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工作,而不使用配置文件,只有代码?

ServiceStack Soap 1.2 HTTPS Client

我相信你的问题在你的配置文件中,尝试添加到绑定标记中。关于此ServiceStack。集成测试你应该有

<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" />

你需要有2个独立的基址,一个用于HTTP,一个用于HTTPS。

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

配置文件的问题是,它并不总是直截了当的,有时是不实用的。在此基础上,ServiceStack促进了少配置的编码模型。

我设法使用以下ssl中立的客户端实现了所需的功能: <>之前Soap12ServiceClient: Soap12ServiceClient{public SoapServiceClient(string uri): base(uri){如果(uri.StartsWithIgnoreCase (" https://")){var binding = (WSHttpBinding)base.Binding;binding.Security.Mode =安全模式。transport;}}}