【发布时间】:2013-05-26 06:49:18
【问题描述】:
我想将我的 WCF 服务从 WebSite App_Code 文件夹迁移到项目库。 据我所知,WCF 库能够读取有关服务模型的 Web 配置,所以我所做的唯一操作是: 1 - 创建新的项目库并将所有关于 wcf 的代码从 app_code 放入其中。 2 - 修改 web 配置以指向具有完整限定名的服务类(命名空间 + 类名) 3 - 修改 svc 文件以指向具有完整限定名称的服务类实例。
但是,我的服务不再运行。我正在使用带有自定义验证器的 ws-httpbinding,但似乎我的服务需要一个基本的 http 绑定。 我正在努力解决的错误如下所示: 消息的请求必须受到保护,例如合约操作要求('IMyService','http://tempuri.org/')。保护必须通过 ('BasicHttpBinding','http://tempuri.org/') 绑定来实现。
@@EDIT:
我的 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 中的服务合同如下所示:
[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 代码。
-
您应该发布您的代码 - 配置的服务模型部分和服务合同。
-
刚刚编辑了所有内容..
-
您可能对服务合同的默认命名空间有问题 - tempuri.org。
-
我不知道。你有什么建议我解决这个问题吗?