Cannot resolve / use System.ServiceModel.Security.WSTrustServiceContract as a service name

I have a WCF issuer service using Microsoft.IdentityModel (WIF 3.5), which I need to upgrade to System.IdentityModel (.NET 4.5). The problem is that I cannot change the original name of the service, Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract , to it a newer copy, System.ServiceModel.Security.WSTrustServiceContract . For some reason, it is not recognized by IntelliSense:

enter image description here

Blue line error:

 The 'name' attribute is invalid - The value 'System.ServiceModel.Security.WSTrustServiceContract' is invalid according to its datatype 'serviceNameType' 

I have links to the System.ServiceModel and System.IdentityModel <assemblies> in the <assemblies> node.

Even when I ignore the IntelliSense error and start the service and access it using a browser, I get this metadata error:

 Metadata publishing for this service is currently disabled. 

Metadata publishing is enabled, so I think this is due to a service name issue.

I also get this error from the VS.NET WCF Test Client:

 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. 

I think the line " Metadata contains a reference that cannot be resolved " also refers to a service name resolution error.

Any ideas on what to do here? I would appreciate any help.

Issuer.svc:

 <%@ ServiceHost Language="C#" Debug="true" Factory="Identity.Services.Wcf.Core.CustomSecurityTokenServiceContractFactory" Service="CustomSecurityTokenServiceConfiguration" %> 

Factory:

 public class CustomSecurityTokenServiceContractFactory : WSTrustServiceHostFactory .. 

Services:

 public class CustomSecurityTokenServiceConfiguration : SecurityTokenServiceConfiguration .. 
+5
source share
2 answers

Sometimes the best way to solve such problems is to create a new WCF project from scratch, configure endpoints again, etc. and copy your existing services from an old project, this is especially true when upgrading from an older version of WCF.

Here is a checklist that I follow every time I have problems with WCF services:

Server

Make sure your service contracts are defined using interfaces with the appropriate attributes, for example:

IMyService.cs

 [ServiceContract] public interface IMyService { [OperationContract] int ThisAnOperation(int a, int b); } 

Make sure that you have completed your contracts using the correct interface:

MyService.cs

 public class MyService: IMyService { public int ThisAnOperation(int a, int b) { return a * b; } } 

You need to have a host service to access your service, these are files with the extension .svc:

  • Create the myService.svc file.
  • Add the following line of code, referencing the class that implements your service:

    <%@ ServiceHost Language="C#" Debug="true" Service="YourNamespace.MyService" CodeBehind="MyService.cs" %>

Finally, you need to set up a binding that will determine which transports and protocols are available to access your server, start with a simple basic HTTP binding to check if your service is working as expected, and then change it to something more ready-made, which includes checking authenticity and / or encryption and compression as necessary.

To establish a basic HTTP binding:

  • Remove the <system.serviceModel>...</system.serviceModel> block from your web.config file, if it already exists.

  • Create your own solution, it must compile successfully, otherwise fix any error and try again.

  • Right-click the web.config file and select "Edit WCF Configuration", then click "Create New Service" and in the "Service Type" field, locate and select the DLL file generated when compiling your service (should be in the bin folder) and select the class of service you want to publish:

Service selection

  1. Indicate the contract for the service (should be automatically filled).

  2. On the next page, select the transport protocol for your service, in this case "HTTP", then select "Interactive Compatibility for Basic Web Services".

  3. On the next page you can specify the address for the endpoint, for testing purposes you can leave this field empty (make sure that you also deleted "HTTP" from the text field).

  4. Click "Next", close the configuration window and save.

Now you can start the service and go to MyService.svc to access your service.

  1. Activate the publication of metadata so that your service can be found, to do this, add the following to your 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> 

Now you can run your project and get a page for describing the metadata of your service in a browser, this information can be used by clients to find a service and create a service proxy:

Customer

  • Remove any existing service links from your project.
  • Right-click on the name of your project, then in "Add a link to a service", enter your business address and click "Go", if everything went fine, you should see your service in the service window:

Service link

  1. Try creating a proxy server by completing the wizard, rebuild your project and try it. If you still have the same problem, delete the generated link and repeat steps 1 and 2, and then:

  2. Click "Advanced" and uncheck "Reuse types in reference assemblies":

Additional service options

Then finish the wizard and compile.

Hope everything should work now!

+3
source

I may have the same setting as yours. In my case, I have both STS and a service called by those who want a token. This is what you have, right?

In Web.config for the actual STS, I have:

 <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> 

And in Web.config for the service, I have:

 <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> 

Also, it works for me here, although I get the same IntelliSense error as you, and in the same place.

+1
source

Source: https://habr.com/ru/post/1274278/


All Articles