请参阅以下代码:
Windows表单应用
//WindowsFormsApplication1.cproj
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ServiceReferenceInsecure.IService1 s1 = new ServiceReferenceInsecure.Service1Client("WSHttpBinding_IService1");
string name1 = s1.HelloWorld("Ian"); //5
}
}
}
<system.web>
<identity impersonate="true" />
<authentication mode="Windows" /> //App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</system.web>
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy
usesystemdefault="True"
bypassonlocal="False" />
</defaultProxy>
</system.net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding_IService1">
<security mode="Transport" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://hq-wk-is.lincspolice.local/WCFSSL/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IService1"
contract="ServiceReferenceInsecure.IService1" name="BasicHttpsBinding_IService1" />
<endpoint address="http://hq-wk-is:86/WCFSSL/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReferenceInsecure.IService1"
name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="3212627@lincspolice.local" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
服务1
//Service1.svc.cs
public class Service1 : IService1
{
public string HelloWorld(string value)
{
return "Hi " + value;
}
}
//Web.Config
?xml version="1.0"?>
<configuration>
<system.net>
<defaultProxy>
<proxy
usesystemdefault="True"
bypassonlocal="False" />
<!--<proxy bypassonlocal="False" usesystemdefault="True" />-->
</defaultProxy>
</system.net>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService2" />
<binding name="BasicHttpsBinding_IService2">
<security mode="Transport" >
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://hq-wk-is:86/WCFSSL2/Service2.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService2" contract="ServiceReference1.IService2"
name="BasicHttpBinding_IService2" />
<endpoint address="https://hq-wk-is.lincspolice.local/WCFSSL2/Service2.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IService2"
contract="ServiceReference1.IService2" name="BasicHttpsBinding_IService2" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
<add binding="wsHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
当我运行此代码时;我看到了预期的结果。但是,当我回顾Fiddler时,我会看到如下所示的四个会话:
为什么WSHttpBinding有四个会话?我使用BasicHttpBinding时只有一个会话。