none
WSE SetPolicy equivalent in WCF RRS feed

  • Question

  • I am trying to convert our old WSE service to WCF, but there does not seem to be a WCF version of SetPolicy();

    Is there a different way to do this in WCF?

    public class UploadService : System.Web.Services.Protocols.SoapHttpClientProtocol
    {
    ...
    }
    
    
    public sealed class MyUploadServiceClient: IDisposable
    {
        readonly UploadService _uploadSvc;
    
        public MyUploadServiceClient(NetworkCredential credentials)
        {
    
            _uploadSvc = new UploadService();
            _uploadSvc.Credentials = credentials;
            _uploadSvc.PreAuthenticate = true;
            
            ((UploadService)_uploadSvc).UserID = credentials.UserName;
            ((UploadService)_uploadSvc).Password = credentials.Password;
    
            // init the code to remove WSA headers
            Policy p = new Policy();
            p.Assertions.Add(new RemoveWSAHeadersFilterAssertion());
            _uploadSvc.SetPolicy(p);
    
        }
    }

    Wednesday, June 10, 2015 2:33 PM

Answers

  • Hi Scott,
       According to your case, I have shared the corresponding details below :
    1.Goto your corresponding config file , then Change the security mode as "TransportWithMessageCredential" like below:
    <basicHttpBinding>
            <binding name="SoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
    </basicHttpBinding>
    
    2.then you can change your code like below :

    public MyUploadServiceClient(NetworkCredential credentials) { SoapClient _uploadSvc = New SoapClient();

    _uploadSvc.ClientCredentials.UserName.UserName = credentials.UserName; _uploadSvc.ClientCredentials.UserName.Password =credentials.Password; Policy p = new Policy(new UsernameOverTransportAssertion()); _uploadSvc.SetPolicy(p); }

    for more information, Click here to refer about Migrating WSE 3.0 Web Services to WCF .
    Thursday, June 11, 2015 2:51 AM