我有一个令牌发行者WCF服务,它使用Microsoft.IdentityModel(WIF 3.5),我需要升级到System.IdentityModel(.NET 4.5)。问题是,我无法将服务的原始名称Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract
更改为新版本的System.ServiceModel.Security.WSTrustServiceContract
。出于某种原因,智能感知无法识别它:
蓝色波浪线错误是:
The 'name' attribute is invalid - The value 'System.ServiceModel.Security.WSTrustServiceContract' is invalid according to its datatype 'serviceNameType'
我对System.ServiceModel
节点中的System.IdentityModel
和<assemblies>
进行了汇编引用。
即使我忽略了IntelliSense错误并运行服务并使用浏览器访问它,我也会收到此元数据错误:
Metadata publishing for this service is currently disabled.
元数据发布已启用,所以我认为这是因为该服务的名称问题。
此外,我从VS.NET WCF测试客户端收到此错误:
Error: Cannot obtain Metadata from http://localhost:49178/Services/Issuer.svc
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://localhost:49178/Services/Issuer.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:49178/Services/Issuer.svc'.
There was no endpoint listening at http://localhost:49178/Services/Issuer.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
HTTP GET Error
URI: http://localhost:49178/Services/Issuer.svc
The HTML document does not contain Web service discovery information.
我认为“Metadata contains a reference that cannot be resolved
”行也指服务名解析错误。
关于该怎么做的任何想法?我很感激任何帮助..
Issuer.svc:
<%@ ServiceHost Language="C#" Debug="true" Factory="Identity.Services.Wcf.Core.CustomSecurityTokenServiceContractFactory" Service="CustomSecurityTokenServiceConfiguration" %>
工厂:
public class CustomSecurityTokenServiceContractFactory : WSTrustServiceHostFactory
..
服务
public class CustomSecurityTokenServiceConfiguration : SecurityTokenServiceConfiguration
..
答案 0 :(得分:3)
有时解决此类问题的最佳方法是从头开始创建一个新的WCF项目,再次配置您的终端等......并从旧项目复制现有服务,从旧版本移动时尤其如此WCF的版本。
以下是每次遇到WCF服务问题时都会遵循的清单:
服务器
确保使用具有适当属性的接口定义服务合同,例如:
<强> IMyService.cs 强>
[ServiceContract]
public interface IMyService
{
[OperationContract]
int ThisAnOperation(int a, int b);
}
使用正确的界面检查您是否已实施合同:
<强> MyService.cs 强>
public class MyService: IMyService
{
public int ThisAnOperation(int a, int b)
{
return a * b;
}
}
您需要有服务主机才能访问您的服务,它们是扩展名为.svc的文件:
添加以下代码行,引用实现服务的类:
<%@ ServiceHost Language="C#" Debug="true" Service="YourNamespace.MyService" CodeBehind="MyService.cs" %>
最后,您需要设置一个绑定,它将定义哪些传输和协议可用于访问您的服务器,从一个简单的基本HTTP绑定开始,检查您的服务是否按预期工作,然后将其更改为更多生产准备就绪,包括身份验证和/或加密和压缩。
设置基本HTTP绑定:
从文件web.config中删除阻止<system.serviceModel>...</system.serviceModel>
(如果已经存在)。
构建您的解决方案,它应该成功编译,否则修复任何错误,然后重试。
右键单击您的web.config文件,然后单击&#34;编辑WCF配置&#34;,然后单击&#34;创建新服务&#34;在服务类型中,浏览并选择编译服务时生成的DLL文件(应位于bin文件夹中)并选择要发布的服务类:
指定服务合同(应自动填写)。
在下一页中选择服务的传输协议,在本例中为&#34; HTTP&#34;,然后选择&#34;基本Web服务互操作性&#34;。
< / LI>在下一页中,您可以指定端点的地址,出于测试目的,您可以将此字段留空(确保您还从文本字段中删除&#34; HTTP&#34;)< / p>
单击“下一步”,关闭配置窗口并保存。
现在您应该能够运行该服务并浏览到MyService.svc以访问您的服务。
激活元数据发布,以便找到您的服务,为此,将以下行为添加到您的web.config中:
<system.serviceModel>
<services>
<service name="WcfService1.MyService">
<endpoint binding="basicHttpBinding"
bindingConfiguration="" contract="WcfService1.IMyService"
BehaviorConfiguration="MyServiceBehaviors" />
</service>
</services>
</system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
现在,您应该能够在浏览器中运行项目并获取服务的元数据描述页面,客户可以使用此信息查找服务并生成服务的代理:
客户
答案 1 :(得分:1)
我可能有与您相似的设置。就我而言,我既有STS,也有想要令牌的人调用的服务。这就是你拥有的,对吧?
在实际STS的Web.config中我有:
<bindings>
<ws2007HttpBinding>
<binding name="ws2007HttpBindingConfiguration">
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false" clientCredentialType="Certificate"/>
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<services>
<service name="System.ServiceModel.Security.WSTrustServiceContract" behaviorConfiguration="STSBehavior">
<endpoint address="IWSTrust13" binding="ws2007HttpBinding" bindingConfiguration="ws2007HttpBindingConfiguration" contract="System.ServiceModel.Security.IWSTrust13SyncContract" name="STSWCF"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
在我所拥有的服务的Web.config中:
<protocolMapping>
<!-- We want to use ws2007FederationHttpBinding over HTTPS -->
<add scheme="https" binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationHttpBindingConfiguration"/>
</protocolMapping>
<bindings>
<ws2007FederationHttpBinding>
<binding name="ws2007FederationHttpBindingConfiguration">
<!-- We expect a bearer token sent through an HTTPS channel -->
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false">
<issuerMetadata address="https://localhost/Identity.STS.WCF/Service.svc/mex"/>
</message>
</security>
</binding>
</ws2007FederationHttpBinding>
</bindings>
<services>
<service name="Identity.Auth.WCF.Service" behaviorConfiguration="STSBehavior">
<endpoint address="https://localhost/Identity.Auth.WCF/Service.svc" binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationHttpBindingConfiguration" contract="Identity.Auth.WCF.IService" name="Identity.Auth.WCF"/>
</service>
</services>
此外,它确实适用于我,即使我确实得到了与您相同的IntelliSense错误,并且在同一位置。