Note that there are some explanatory texts on larger screens.

plurals
  1. POMonoTouch WCF REST Error Creating Channel
    primarykey
    data
    text
    <p>I'm trying to access WCF REST services via MonoTouch. I am unable to use a ChannelFactory, as dynamic code generation is not possible in MonoTouch, and because I'm accessing RESTful services, I'm also unable to use svcutil to build the client classes.</p> <p>This leaves me with building the client classes manually. I've gotten quite far but have hit a problem, here is my code for the proxy class:</p> <pre><code>public class AuthenticationClient : System.ServiceModel.ClientBase&lt;IAuthenticationService&gt;, IAuthenticationService { public AuthenticationClient(Binding binding, EndpointAddress baseAddress) : base(binding, baseAddress) { } public AuthenticationResult AuthenticateUser (AccountCredentials credentials) { return base.Channel.AuthenticateUser(credentials); } protected override IAuthenticationService CreateChannel () { // This method must be overriden in MonoTouch to prevent using a ChannelFactory return new AuthenticationChannel(this); } private class AuthenticationChannel : ChannelBase&lt;IAuthenticationService&gt;, IAuthenticationService { public AuthenticationChannel(System.ServiceModel.ClientBase&lt;IAuthenticationService&gt; client) : base(client) { } public AuthenticationResult AuthenticateUser (AccountCredentials credentials) { object[] _args = new object[1]; _args[0] = credentials; return (AuthenticationResult)base.Invoke("AuthenticateUser", _args); // Exception thrown here } } } </code></pre> <p>The interface IAuthenticationService uses attributes to specify the endpoint Uri's:</p> <pre><code>[ServiceContract] public interface IAuthenticationService { [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/Authenticate/User")] AuthenticationResult AuthenticateUser(AccountCredentials credentials); } </code></pre> <p>Here is how I'm using the proxy class:</p> <pre><code>var serviceHost = "http://mydomain.com/"; var servicePath = "Services/Authentication"; Uri hostUri = new Uri(serviceHost); Uri serviceUri = new Uri(hostUri, servicePath); var binding = new WebHttpBinding(); var client = new AuthenticationClient(binding, new EndpointAddress(serviceUri)); client.Endpoint.Behaviors.Add(new MyWebHttpBehaviour()); var credentials = new AccountCredentials { Username = "myusername", Password = "mypassword" }; var result = client.AuthenticateUser(credentials); </code></pre> <p>(For some reason WebHttpBehavior does not implement IEndpointBehavior, so I created my own class that inherits from WebHttpBehavior and also implements IEndpointBehavior).</p> <p>The exception I receive is:</p> <p><strong>System.InvalidOperationException: When manual addressing is enabled on the transport, every request messages must be set its destination address.</strong></p> <p>Can anyone help?</p> <p>Cheers, Anthony.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload