2013-05-30 116 views
1

我想將我的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 
} 

有什麼想法?

+0

應該可能顯示你的web.config代碼。 – Jake

+0

你應該發佈你的代碼 - 配置的servicemodel部分和servicecontract。 –

+0

剛編輯過的東西.. – bit

回答

1

我解決了。 這個問題是關於在web配置上缺少dll名稱的問題。

我不得不改變我的配置如下:

第一:

<userNameAuthentication userNamePasswordValidationMode="Custom" 
     customUserNamePasswordValidatorType="="MyWcfNamespaceOfMyDLL.MyCustomValidator", MyDllName" /> 

二:

<services> 
     <service behaviorConfiguration="MyBehavior" 
       name="MyWcfNamespaceOfMyDLL.MyServiceName"> 
     <endpoint address="" binding="wsHttpBinding" 
        contract="IMyServiceName" bindingConfiguration="MyBinding"> 
      <identity> 

我想每個人都可以開始瘋了.. !!

好吧,你可以看到,我只好:

  • 上userNameAuthentication標籤指定的DLL名稱。
  • 在服務標籤的屬性名稱上指定名稱空間名稱。
  • 刪除有關終結點標記的契約屬性上名稱空間名稱的規範。

好吧,我已經解決了,但我有點擔心未來的未來..!

0

您確定問題來自服務而不是客戶端的

您能告訴我們您如何致電此服務?

消息的請求必須被保護,如需要通過合同操作(「IMyService」,「http://tempuri.org/」)。 保護必須通過 ('BasicHttpBinding','http://tempuri.org/')綁定實現。

至於說here

如果綁定不支持安全性(如basicHttpBinding的), 有效System.Net.Security.ProtectionLevel是 ProtectionLevel.None整個合同。結果是 取決於端點綁定,即使合同 指定了ProtectionLevel.None,客戶端也可能要求不同的 消息或傳輸級安全保護。

此錯誤消息建議您使用不帶ProtectionLevel的basicHttpBinding調用該服務。

此外,您的Web.config IMyServiceName中的合同與您的代碼'IMyService'或錯誤消息中的合同不同。

+0

IMyServiceName和IMyService一直是我的錯誤唯一的關鍵。是的,我與你打交道,但我無法從任何客戶端添加服務引用。另外,我會記住你我在將服務代碼移入dll項目後遇到了這個問題。當我的服務在asp.net中完成時,一切正常。我使用服務器證書進行保護,但我再重複一次,如果撤消所有修改,並將我的服務接口置於app_code中,則一切正常。 – bit