views:

817

answers:

3

First off, I'd like to thank those who have helped me out with this WCF connectivity, as it's fairly new to me.

I've got a hosted WCF service that I created a custom factory for, so that this would work with multiple host headers:

/// <summary>
/// Required for hosting where multiple host headers are present
/// </summary>
public class MultipleHostServiceFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        List<Uri> addresses = new List<Uri>();
        addresses.Add(baseAddresses[0]);
        return base.CreateServiceHost(serviceType, addresses.ToArray());
    }
}

I'm pretty sure that my config files are now right, on both client and server (can be seen here http://stackoverflow.com/questions/1794247/wcf-consumer-website-returning-the-address-property-on-channelfactory-endpoint-wa ).

The error I'm getting appears to be related to the factory:

Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.

Line 113:
Line 114: public string GetData(int value) { Line 115: return base.Channel.GetData(value); Line 116: } Line 117:

The error occurs at line 115.

Thanks.

A: 

I don't think this necessarily has anything to do with your factory.

See

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.manualaddressing.aspx

or others among the first few Bing hits for "manualaddressing". It sounds like the binding being used is incompatible with some other portion of the stack/messaging logic.

Brian
Well, I'm not using custom biding - using web webHttpBinding - defined in both. Initially a problem was that the client only had custom binding defined (I simply made a service reference to my WCF server and let VS do the rest). Still looking into this new error...
ElHaix
'add service reference' and 'webHttpBinding' don't work together well, and would explain the error. I think your client is trying to talk SOAP using a WS-Addressing binding to your REST-y service that just speaks HTTP.
Brian
See e.g. http://damianm.com/tech/building-a-rest-client-with-wcf/
Brian
So using svcutil.exe to create my WCF client would be a better route?
ElHaix
No; if you are using webHttpBinding, then neither svcutil nor add service reference are good. You either want to hand-code the client (share contract types etc) or use a 'generic' http client that just speaks the universal REST/CRUD interface.
Brian
Yeah, I realize that - just generated the proxy class, re-config'ed it all and getting the same error. Ok, so since I'm going through HTTPS do I have to use webHttpBinding? I just need to get a basic service up and running on this host so we can leap off from there.
ElHaix
You don't have to use webHttp to get https, you can use basicHttp/wsHttp and do https, the axis here is REST v SOAP (web v basic/ws)
Brian
I've also tried switching back to the customBinding, where I added httpTransport manualAddressing="false" - and now getting "The remote server returned an error: (405) Method Not Allowed. As per your recommendation I switched it all to use wsHttpBinding and I'm still getting the same 405 error.
ElHaix
If you are getting a 405, this means the server and client bindings are mismatched (one is using webHttp and thus the GET method, and one is using wsHttp and thus the POST method).
Brian
A: 

So this has finally come to an end!

Brian - thanks for your guidance on this. The bindings were mis-aligned b/t the client and server, and I finally ended up going with the following in both:

  <basicHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>

... and setting their endpoint binding and bindingConfiguration attributes accordingly:

   <endpoint binding="basicHttpBinding" bindingConfiguration="TransportSecurity"
    contract="ServiceReference1.IService" 
    name="WebHttpBinding_IService" 
    address="https://mysslserver.com/Service.svc" />

Since this is relatively new turf for me, just the explanation of why those errors were popping up lead me in the right direction :).

Finally I can go back to writing code instead of flipping switches in config files! :)

Thanks!

ElHaix
+1  A: 

I experienced this error and the problem was resolved by adding the WebHttpBehavior (line 2 below):

var factory = new ChannelFactory<IService>(new WebHttpBinding(), uri);
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();
bendewey