Hi,
I’m trying to port over some existing WCF extension code into a Xamarin app that is targeting iOs, WinPhone and Android. The code currently lives in a windows desktop app without any problems.
Essentially, all the code does is catch every outgoing WCF service call and appends some http headers, then catches the response and reads any headers which have been returned. This is achieved using a custom behaviour and IClientMessageInspector in code and configured in the app.config in my existing windows desktop app:
<behaviors>
<endpointBehaviors>
<behavior>
<MyBehavior ConsumerKey="878846DF-2E7B-4165-8542-9F68583DD7D4" ConsumerType="Windows Forms" />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="MyBehavior" type="MyBehavior.Objects.ServiceLayer.WCFExtensions.ConsumerBehaviorElement, MyBehavior.Objects.ForConsumers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
Unfortunately, I don’t seem to have an app.config in my Xamarin project so started to look at manually adding the behaviour via code. I have seen lots of examples showing the use of:
myServiceClient.Enpoint.Behaviors.Add(…)
However, I don’t seem to have access to the Behaviors property of my Endpoint (System.ServiceMode.Description.ServiceEndpoint) from the App.cs in my Xamarin app. I only have access to Address, Binding, Contract and Name.
Can anyone point me in the right direction with this. As mentioned above, all I want to do is attach some headers to every WCF service call, and read some headers on the response.
Some more information:
An example of calling my WCF service is as follows:
private void CallService()
{
MyAuthenticationService.AuthenticationServiceClient _ws = new MyAuthenticationService.AuthenticationServiceClient();
_ws.AuthenticateCompleted += _ws_AuthenticateCompleted;
_ws.AuthenticateAsync(new MyAuthenticationService.AuthenticationRequest1());
}
private void _ws_AuthenticateCompleted(object sender, MyAuthenticationService.AuthenticateCompletedEventArgs e)
{
throw new NotImplementedException();
}
And finally, my Xamarin project is targeting:
.Net Framework 4.5
Windows 8
Windows Phone Silverlight 8
Xamarin.Android
Xamarin.iOs
Xamarin.iOS (Classic
)
Thanks
David