gpt4 book ai didi

WCF:如何对 SSL 服务执行 "Add Service Reference"(我收到错误)

转载 作者:太空宇宙 更新时间:2023-11-03 12:52:08 24 4
gpt4 key购买 nike

FooService.svc.cs:

[ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
public interface IFooBar
{
[OperationContract()]
int Add(int num1, int num2);
}

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class FooService : IFooBar
{
public int Add(int num1, int num2)
{
return num1 + num2;
}
}

Web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<system.web>
<customErrors mode="Off"/>
<globalization culture="en-US" uiCulture="en-US" />
<compilation defaultLanguage="c#" targetFramework="4.0" />
</system.web>

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<defaultDocument>
<files>
<add value="index.aspx" />
</files>
</defaultDocument>
</system.webServer>

<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>

<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
</sharedListeners>
</system.diagnostics>

</configuration>

我将文件发布到我的服务器(上面有 ssl 证书),但是当我转到网页时:https://localhost:443/FooService.svc我收到以下错误...

The request message must be protected. This is required by an operation of the contract ('IFooBar','http://tempuri.org/'). The protection must be provided by the binding ('BasicHttpBinding','http://tempuri.org/').

无论我直接转到 url 还是从 Visual Studio 中转到 Add Service Reference...,都会发生这种情况。


此外,如果我将 [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)] 更改为 [ServiceContract],它工作正常。

最佳答案

WCF 4 中 HTTP 传输的默认绑定(bind)是 basicHttpBinding。当您将服务契约(Contract)保护级别设置为加密和签名时,绑定(bind)还必须支持消息级别安全性。由于 basicHttpBinding 不支持消息级安全,您需要手动将服务配置为 wsHttpBinding 或更改协议(protocol)映射如下:

<system.serviceModel>
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="" />
</protocolMapping>
... snip ...
</system.serviceModel>

关于WCF:如何对 SSL 服务执行 "Add Service Reference"(我收到错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com