WCF-Client custom endpoint behavior set protectionlevel

2.4k Views Asked by At

I'm trying to call a java webservice from a WCF client.

The Java service uses WSE 3.0 security, so I'm using a custom binding and in the Reference.cs file of the service If I change the service contract to use protectionlevel.sign and everything is working fine.

Now the problem is I need to call this service from BizTalk. but I have no way to set the protectionlevel to sign and the calls to the service fails.

I'm trying to write a custom behavior that derives from ClientCredentials behavior and override the ApplyClientBehavior method to set the protection level like this:

public override void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.ClientRuntime behavior)
{
        base.ApplyClientBehavior(serviceEndpoint, behavior);
        serviceEndpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;

}

But this is not working it fails with the same error as if the proctionlevel was set to default. If I inspect the contract endpoint in debug the protection level is set to sign but it has no effect.

Then I tried to remove the protectionlevel.sign from the service contract in the reference.cs file and use the clientcredentials behavior instead and before the call to service, set the protectionlevel to sign in code like this.

Service.ServiceClient client = new Service.ServiceClient();
client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;

var result = client.GetData();

And this works fine. But I can't do this in BizTalk

Anyone have a clue why above code works, but the custom endpoint behavior don't?

0

There are 0 best solutions below