Problems connecting to WCF with in-code client
I'm tr开发者_如何学Cying to connect to a WCF service with an in-code configured client. The host is configured through web.config file. I get exception "The remote server returned an error: (405) Method Not Allowed." I've test it with self-hosting and it worked but I can't get it too work when it's running on it's own. I'm trying to get it too work with VS devenv local hosting.
<system.serviceModel>
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
var uri = new Uri("http://localhost:8000/MyService");
var address = new EndpointAddress(uri);
var factory = new ChannelFactory<IMyService>(new BasicHttpBinding(), address);
IMyService service = factory.CreateChannel();
service.DoSomething(); <-- fails here
Figured it out. Apparently when using a non-self hosted option then the client endpointaddress must include .svc at the end.
精彩评论