FooService.svc.cs:WCF:如何做 「添加服務引用」 到SSL服務(遇到錯誤)
[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我得到以下錯誤...
請求消息必須受到保護。 這是 合同 ('IFooBar','http://tempuri.org/')的操作所要求的。 保護必須由 綁定 ('BasicHttpBinding','http://tempuri.org/')提供。
無論我直接轉到url還是從Visual Studio中轉到Add Service Reference...
,都會發生這種情況。
另外,如果我改變[ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
到[ServiceContract]
它工作正常。
我愛你man! :) <3 – michael 2011-05-02 15:52:58