WCF サービスを使用するプロジェクトに取り組んでいます。サービスを構築し、web.config ファイルを構成し、IIS 7 サーバーに展開しました。サービスは HTTPS 経由でアクセスされます (私の開発マシンでは、証明書を自己作成しました)。Visual Studio 2010 で ServiceReference を作成すると、すべて問題なく、クライアントが作成され、正常に動作します。
必要なのは、クライアントをプログラムで作成することです (少し柔軟性が必要です)。そのため、「手動で」接続しようとすると、次のようなエラーが表示されます。
指定された URI スキーム「https」は無効です。「http」が必要です。パラメータ名:経由
web.config のコードは次のとおりです (問題がないことを願っています)。
<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();
//....................................
}
私はここで何か間違ったことをしているようです.プロシージャは私が言及した例外を発生させます. 仕事のためにもっとやらなければならないことがありますが、私はそれを理解していませんでした。
あなたが私に与えることができるアドバイスを前もって感謝します。