我在我的IIS中安装了自我https证书,并在本地计算机中将我的EchoService从http更改为https。
但是在选择传输服务后,我得到了以下错误。
带有操作的消息''由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的约束(包括安全要求,例如邮件,传输,无)。
客户端应用配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="EchoService">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://desktop-rfd4j23/WCFASPNETSecurityEx/EchoService.svc" binding="wsHttpBinding"
bindingConfiguration="EchoService" contract="EchoService.IEchoService" name="EchoService">
</endpoint>
</client>
</system.serviceModel>
</configuration>
服务网站配置:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.2"/>
<httpRuntime targetFramework="4.6.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="wsHttp" hostNameComparisonMode="Exact">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WCFASPNETSecurityEx.EchoServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WCFASPNETSecurityEx.EchoServiceBehavior" name="WCFASPNETSecurityEx.EchoService">
<endpoint binding="webHttpBinding" bindingConfiguration="wsHttp"
name="EchoService" contract="WCFASPNETSecurityEx.IEchoService">
</endpoint>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
客户代码:
Console.WriteLine("Press Enter when the web server is started");
Console.ReadLine();
EchoServiceClient client = new EchoServiceClient();
String result = client.Echo("Hello WCF");
Console.WriteLine(result);
Console.ReadLine();
我在调用client.Echo时遇到错误(&#34; Hello WCF&#34;);请帮我解决这个问题。感谢。
答案 0 :(得分:0)
我应该提到wsHttpBinding而不是webHttpBinding。
<bindings>
<wsHttpBinding>
<binding name="wsHttp" hostNameComparisonMode="Exact">
<security mode="Transport" >
<transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport>
<message clientCredentialType="UserName"></message>
</security>
</binding>
</wsHttpBinding>
</bindings>
答案 1 :(得分:0)
您使用https锁定传输并要求进行UserName身份验证。 安全模式不应设置为:
private async void buttonLoad_Click(object sender, RoutedEventArgs e)
{
XmlSerializer serializer = new XmlSerializer(personneList.GetType());
StorageFolder folder = ApplicationData.Current.LocalFolder;
using (var stream = await folder.OpenStreamForReadAsync("users.xml"))
{
personneList = (List<Model.Personne>)serializer.Deserialize(stream);
}
}
您是否在任何地方都在客户处理?
<security mode="TransportWithMessageCredential" >