原创地址:
转载请注明出处
如何在WCF中使用Transport Security Mode,以及如何创建证书,请参见,本文介绍如何使用Basic clientCredentialType。
server web.config
client app.config:
public partial class Form1 : Form { DemoServiceReference.DemoServiceClient demoServiceClient; public Form1() { InitializeComponent(); demoServiceClient = new DemoServiceReference.DemoServiceClient(); demoServiceClient.ClientCredentials.UserName.UserName = "alex"; demoServiceClient.ClientCredentials.UserName.Password = "123456"; } private void buttonCalculate_Click(object sender, EventArgs e) { try { textBoxResult.Text = demoServiceClient.Divide(Convert.ToInt32(textBoxNumerator.Text), Convert.ToInt32(textBoxDenominator.Text)).ToString(); } catch (FaultExceptionfault) { MessageBox.Show(fault.Detail.Error + " - " + fault.Detail.Detail); } } }
调用成功。