ServiceStack Soap 1.2 HTTPS 客户端

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一起工作?

请添加您托管服务的代码/配置。 - silver
@silver 没有配置文件。我添加了更多的代码,至少显示了触发异常的 send 调用。SOAP 服务本身不是基于 ServiceStack 的服务(仅客户端),但无论如何,该代码实际上都没有到达另一端的服务器。 - Paul Rooney
3个回答

6

我认为你的问题在于配置文件中,尝试向绑定标签添加<bindingInformation>。关于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" />


我实际上没有配置文件。所以创建一个可能是正确的方法。我会尝试一下,谢谢。 - Paul Rooney
你可以使用我回答中提供的链接来完成所有必要的配置,此外这个链接也可能会有所帮助 https://github.com/ServiceStack/ServiceStack/wiki/Config-API - Hussein Khalil

3

在使用it技术时,你需要有两个不同的基础地址,一个用于HTTP,另一个用于HTTPS。

你可以在配置文件中或者在托管代码中定义这些基础地址。


我该如何在代码中实现?如果可以的话,我宁愿避免配置。这只是一个测试应用程序,没有什么严重的问题。 - Paul Rooney
创建服务主机时,您需要提供一个 URI 数组,因此请同时提供两个协议 (new ServiceHost(MyService, new []{"http://myService/","https://myService/"}))。 - silver

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; } } } ```

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接