我正在使用WCF服务的项目。我已经构建了该服务,配置了web.config文件,并将其部署在IIS 7服务器上。该服务通过HTTPS加密(在我的开发机器上,我自己创建了证书)。 在Visual Studio 2010中创建ServiceReference时,一切都很好,它创建客户端并且工作正常。通过HTTPS以编程方式连接到WCF服务
我需要的是一个以编程方式创建一个客户端(需要一点点的灵活性),所以当我尝试“手动”连接,它给了我这样一个错误:
The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
用于Web的代码。配置为:(我希望没有什么错吧)
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="WcfService1.IService1" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
我写访问WCF服务的过程是:
void proc()
{
string ADRESASSL = "https://localhost/ServiciuSSLwsBind/Service1.svc";
WSHttpBinding bind= new WSHttpBinding();
EndpointAddress ea = new EndpointAddress(ADRESASSL);
var myChannelFactory = new ChannelFactory<IService1>(bind, ea);
IService1 client = null;
try
{
client = myChannelFactory.CreateChannel();
client.RunMethod1();
client.Close();
//((ICommunicationObject)client).Close();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
if (client != null)
client.Close();
}
}
为IService1
[ServiceContract]
public interface IService1 : IClientChannel
{
[OperationContract]
int RunMethod1();
//....................................
}
代码看来我错在这里做什么,该工序会提高我提到的异常。我还需要做更多的工作,但我没有弄明白。
在此先感谢您提供给我的任何建议。
你是如何托管你的服务?该交通工具是否启用了https? – stephenl 2013-02-17 23:37:09