开发者

Why do I get WCF Exception "HTTP could not register URL http://+:80/MyService/"

I create my host with the endpointaddress it needs to use, like this:

Uri endpointAddress = new Uri("http://127.0.0.1:5555/MyService");
ServiceHost host = new ServiceHost(myServiceType, endpointAddress);
host.AddServiceEndpoint(implementedContract, basicHttpBinding, string.Empty);

but when I later do host.Open(); I get the exception "HTTP could not register URL http://+:80/MyService/ because TCP port 80 is being used by another application". The result is the same when I do

host.AddServiceEndpoint(implementedContract, basicHttpBinding, endpointAddress);

Why would it try to do anything with port 80? How can I solve this?

Update While trying to provide a more complete code sample, I found the culprit. I added a ServiceMetadataBehavior as follows:

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.ExternalMetadataLocation = new Uri(this.ExternalMetadataLocation);
smb.HttpG开发者_运维问答etEnabled = true;
smb.HttpGetUrl = this.RemovePort(this.EndpointAddress);
host.Description.Behaviors.Add(smb());

It seems that in the past I needed to remove the port from the URL to get this to work, but now that's exactly what causes the problem.

So Pratik is right: metadata were the problem, and of course the problem with port 80 is that there's some newly installed application using that port.

Thanks, regards,

Miel.


This is because port 80 is already used by another applicatiion as the error message says, most likely by local IIS server. Try stopping IIS and see, or use another port. On vista and above you can use netsh command to check which ports are already reserved

BTW do you have http metadata or mex endpoints in the app.config or web.config file ?


The following works fine for me:

class Program
{
    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        void Test();
    }

    public class MyService : IMyService
    {
        public void Test()
        {
            throw new NotImplementedException();
        }
    }

    static void Main()
    {
        var endpointAddress = new Uri("http://127.0.0.1:5555/MyService");
        using (var host = new ServiceHost(typeof(MyService), endpointAddress))
        {
            var basicHttpBinding = new BasicHttpBinding();
            host.AddServiceEndpoint(typeof(IMyService), basicHttpBinding, string.Empty);
            host.Open();
        }
    }
}

Maybe you have some other code which is interfering?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜