[英]Simple WCF SSL Web Service
我正在機器上創建WCF Web服務,此框是此類型的第一個服務。
我已經有一個運行大量SOA SSL服務的.NET 2.0企業應用程序。
我有一個內部SSL服務器授權,該權限已為我的計算機創建了SSL x509證書。 我也有許多由用於測試的同一證書頒發機構創建的客戶端證書。 所有這些證書都可以在我當前的應用程序中使用。
我正在編寫WCF SSL Web服務以接受純XML消息,現在,吐出每個請求存在的每個HTTPHeader。
我在設置問題時遇到了一些問題。 我沒有SSL就可以正常工作。
當我使用WCF服務(https)時,它會下載並創建對象並正常修改app.config,它也會提示我有關服務器證書的信息。 但是,當我向該WCF服務發送消息時,它出錯了。
我機器上的服務網址:
https://8KZVJS1/HeaderIntercept/HeaderIntercept.svc
當我嘗試提交消息時,我開始收到錯誤消息:
客戶端身份驗證方案“匿名”禁止HTTP請求。
我嘗試修改我的app.config,但現在我只得到:
提供的URI方案“ https”無效; 預期的“ http”。 參數名稱:通過
更新:進行了一些編輯,現在我得到: 在https://8kzvjs1/headerintercept/HeaderIntercept.svc
上沒有端點可以接受該消息。 這通常是由不正確的地址或SOAP操作引起的。 有關更多詳細信息,請參見InnerException(如果存在)。
我需要通過一個簡單的.NET客戶端來完成此工作,然后將其推送,以便我們可以使用Apache反向代理將原始SOAP消息傳遞給它。
有什么想法嗎?
Windows 7-64位。
SSL-不需要,但可以接受
匿名訪問-已啟用。
配置編輯器-system.webServer / security / access SSl,SSLNegotiateCert,SSL128已檢查
WCF Web服務web.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security>
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="HeaderIntercept">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="WCFServiceCertificate.IService1" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</clientCertificate>
<serviceCertificate findValue="8KZVJS1" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
客戶端app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000" >
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://8KZVJS1/HeaderIntercept/HeaderIntercept.svc"
binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
contract="HeaderIntercept.IHeaderIntercept" name="wsHttpEndpointBinding">
<identity>
<dns value="8KZVJS1"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
IHeaderIntercept.cs
[ServiceContract]
public interface IHeaderIntercept
{
[OperationContract]
XElement MCCI_IN200100BC(XElement xml);
}
HeaderIntercept.svc
namespace WCF_Header_Intercept
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class HeaderIntercept : IHeaderIntercept
{
public XElement MCCI_IN200100BC(XElement xml)
{
StringBuilder sb = new StringBuilder();
WebHeaderCollection headers = WebOperationContext.Current.IncomingRequest.Headers;
foreach (string key in headers.Keys) {
sb.AppendLine("header " + key + "=" + headers[key]);
}
OperationContext.Current.IncomingMessageHeaders.AsParallel().ForAll(h => sb.AppendFormat("Name={0}, IsReferenceParameter={1}, MustUnderstand={2}, Namespace={3}, Relay={4}, Actor={5}.{6}", h.Name, h.IsReferenceParameter, h.MustUnderstand, h.Namespace, h.Relay, h.Actor, Environment.NewLine));
System.Diagnostics.Debug.Write(sb.ToString());
return XElement.Parse("<data>" + sb.ToString() + "</data>");
}
}
}
弄清楚了。 與我的合同匹配時,我的web.config綁定錯誤。 我刪除了命名空間,使事情變得更簡單,並使它正常工作。
感謝托馬斯的見解。 希望我可以將其標記為答案:\\
web.config中:
<system.serviceModel>
<services>
<service name="HeaderIntercept" >
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="IHeaderIntercept">
<identity>
<dns value="CGI-8KZVJS1"/>
</identity>
</endpoint>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHeaderIntercept" >
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://cgi-8kzvjs1/HeaderIntercept/HeaderIntercept.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHeaderIntercept"
contract="HeaderIntercept.IHeaderIntercept" name="WSHttpBinding_IHeaderIntercept">
<identity>
<servicePrincipalName value="host/CGI-8KZVJS1" />
</identity>
</endpoint>
</client>
</system.serviceModel>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.