我试图使一个WCF服务在basicHttpBinding上使用https。这是我的web.config:
<!-- language: xml -->
<service behaviorConfiguration="MyServices.PingResultServiceBehavior"
name="MyServices.PingResultService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="defaultBasicHttpBinding"
contract="MyServices.IPingResultService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
...
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
...
<behaviors>
<serviceBehaviors>
<behavior name="MyServices.UpdateServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
我使用WCFStorm连接,它能够正确检索所有元数据,但当我调用实际的方法时,我得到:
提供的URI方案'https'无效;预计“http”。参数
名称:通过
我已经通过Visual Studio添加了一个“连接服务”到我们的项目中,它生成了一个默认方法来创建客户端。
var client = new MyWebService.Client(MyWebService.Client.EndpointConfiguration.MyPort, _endpointUrl);
这个构造函数继承了ClientBase,并且在幕后使用它自己的方法Client.GetBindingForEndpoint(endpointConfiguration)来创建Binding:
public Client(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(Client.GetBindingForEndpoint(endpointConfiguration),
new System.ServiceModel.EndpointAddress(remoteAddress))
此方法对https服务和http服务有不同的设置。
当你想从http获取数据时,你应该使用TransportCredentialOnly:
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly;
对于https,您应该使用Transport:
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
我已经通过Visual Studio添加了一个“连接服务”到我们的项目中,它生成了一个默认方法来创建客户端。
var client = new MyWebService.Client(MyWebService.Client.EndpointConfiguration.MyPort, _endpointUrl);
这个构造函数继承了ClientBase,并且在幕后使用它自己的方法Client.GetBindingForEndpoint(endpointConfiguration)来创建Binding:
public Client(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(Client.GetBindingForEndpoint(endpointConfiguration),
new System.ServiceModel.EndpointAddress(remoteAddress))
此方法对https服务和http服务有不同的设置。
当你想从http获取数据时,你应该使用TransportCredentialOnly:
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly;
对于https,您应该使用Transport:
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;