我想將我的WCF服務從WebSite App_Code文件夾遷移到項目庫。 據我所知,WCF庫能夠讀取有關服務模型的Web配置,所以我做的唯一操作如下: 1 - 創建新的項目庫,並將有關wcf的所有代碼從app_code中提取出來。 2 - 修改web配置以指向具有完全限定名稱(名稱空間+類名稱)的服務類 3 - 修改svc文件以指向具有完全限定名的服務類實例。WCF項目庫
但是,我的服務不再運行。我使用ws-httpbinding與自定義驗證器,但它似乎我的服務期望一個基本的http綁定。 我正在努力的錯誤是這樣的: 消息的請求必須受到保護,如合同操作('IMyService','http://tempuri.org/')所要求的。保護必須通過('BasicHttpBinding','http://tempuri.org/')綁定來實現。
@@編輯:
我的web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyWcfNamespaceOfMyDLL.MyCustomValidator" />
<serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyBinding" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000" messageEncoding="Mtom">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyBehavior" name="MyServiceName">
<endpoint address="" binding="wsHttpBinding" contract="MyWcfNamespaceOfMyDLL.IMyServiceName" bindingConfiguration="MyBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
這是網站的根目錄裏面我的SVC文件:
<%@ ServiceHost Language="C#" Debug="true" Service="MyWcfNamespaceOfMyDLL.MyServiceName" %>
最後,我的DLL裏面的服務contrat出現像這樣:
[ServiceContract]
public interface IMyService
{
[OperationContract(ProtectionLevel=System.Net.Security.ProtectionLevel.EncryptAndSign)]
string DoSomething();
}
public class MyServiceName : IMyService
{
public string DoSomething();
}
public class MyValidator : UserNamePasswordValidator
{
// simple validation
}
有什麼想法?
應該可能顯示你的web.config代碼。 – Jake
你應該發佈你的代碼 - 配置的servicemodel部分和servicecontract。 –
剛編輯過的東西.. – bit