我创建了一个带有证书身份验证的WCF服务,它与WCF客户端完美配合。但问题是当我想通过WebService客户端使用相同的WCF服务时(可能客户端可能只有.net 2.0框架)。
我试图调用的WCF服务方法是
public class Service : IService
{
public string GetWelcomeMessage()
{
return "Consuming WCF Service as Webservice";
}
}
我的WCF服务配置片段如下
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint name="BasicHttpEndPoint" address="" binding="basicHttpBinding" contract="IService" bindingConfiguration="BasicHttpEndPointBinding">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndPointBinding">
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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"/>
<serviceCredentials>
<serviceCertificate findValue="CN=tempServerCert"/>
<!--<clientCertificate>
<authentication certificateValidationMode="ChainTrust"/>
</clientCertificate>-->
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我已在VS2005上创建的ASP.Net 2.0应用程序中添加了WCF服务作为“添加Web Referance”,而我的客户端(ASP.net 2.0应用程序)web.config是
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint name="BasicHttpEndPoint" address="" binding="basicHttpBinding" contract="IService" bindingConfiguration="BasicHttpEndPointBinding">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndPointBinding">
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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"/>
<serviceCredentials>
<serviceCertificate findValue="CN=tempServerCert"/>
<!--<clientCertificate>
<authentication certificateValidationMode="ChainTrust"/>
</clientCertificate>-->
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我在调用WCF服务时收到SoapHandlerException。例外情况如下
Message: An error occurred when verifying security for the message.
InnerException: null
Stack Trace: at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at w15mtc15j128.Service.GetWelcomeMessage() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wcfwebserviceclient\99c8cdb0\4f5c6355\App_WebReferences.e4pgkrzt.0.cs:line 151
at _Default.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\WCFWebServiceClient\Default.aspx.cs:line 17
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)