|
-
Jul 22nd, 2009, 03:06 PM
#1
Thread Starter
Hyperactive Member
WCF example: Self host service is not working
Hello,
I followed the example in MSDN http://msdn.microsoft.com/en-us/library/ms730935.aspx
When I verify if the service is working or not, the result is that it works from visual studio(service.exe) but failed in browsing to the service's debug page at http://localhost:8080/ServiceModelSamples/Service
I am using IE 8 and Windows XP Pro.
Could you please advise me?
Thanks.
Code:
Imports System
Imports System.ServiceModel
Imports System.ServiceModel.Description
Namespace Microsoft.ServiceModel.Samples
Module Service
' Define a service contract.
<ServiceContract([Namespace]:="http://Microsoft.ServiceModel.Samples")> _
Public Interface ICalculator
<OperationContract()> _
Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double
End Interface
' Step 1: Create service class that implements the service contract.
Public Class CalculatorService
Implements ICalculator
' Step 2: Implement functionality for the service operations.
Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Add
Dim result As Double = n1 + n2
' Code added to write output to the console window.
Console.WriteLine("Received Add({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Subtract
Dim result As Double = n1 - n2
Console.WriteLine("Received Subtract({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Multiply
Dim result As Double = n1 * n2
Console.WriteLine("Received Multiply({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Divide
Dim result As Double = n1 / n2
Console.WriteLine("Received Divide({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
End Class
Class Program
Shared Sub Main()
Dim baseAddress As New Uri("http://localhost:8080/ServiceModelSamples/Service")
Dim selfHost As New ServiceHost(GetType(CalculatorService), baseAddress)
Try
selfHost.AddServiceEndpoint( _
GetType(ICalculator), _
New WSHttpBinding(), _
"CalculatorService")
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
selfHost.Description.Behaviors.Add(smb)
selfHost.Open()
Console.WriteLine("The service is ready.")
Console.WriteLine("Press <ENTER> to terminate service.")
Console.WriteLine()
Console.ReadLine()
selfHost.Close()
Catch ce As CommunicationException
Console.WriteLine("An exception occurred: {0}", ce.Message)
selfHost.Abort()
End Try
End Sub
End Class
End Module
End Namespace
-
Jul 22nd, 2009, 03:15 PM
#2
Re: WCF example: Self host service is not working
Are you admin on your machine?
You said it works from within Visual Studio - what do you mean by that. Are you saying that you can browse to the URL while it's self hosted and running from Visual Studio? Or are you saying that the URL in the browser just never works?
-
Jul 22nd, 2009, 03:24 PM
#3
Re: WCF example: Self host service is not working
Yeah you need to explain a little better... but from your code I cant see any reason why anything wouldnt be working, all looks as it should.
-
Jul 22nd, 2009, 03:58 PM
#4
Thread Starter
Hyperactive Member
Re: WCF example: Self host service is not working
 Originally Posted by mendhak
Are you admin on your machine?
You said it works from within Visual Studio - what do you mean by that. Are you saying that you can browse to the URL while it's self hosted and running from Visual Studio? Or are you saying that the URL in the browser just never works?
I mean if I run the code by pressing F5 then a dos window pops up.
However if I paste the ip address to the browser then an error occuried.
Code:
This program cannot display the webpage
And I am the computer adminstrator.
-
Jul 22nd, 2009, 05:37 PM
#5
Re: WCF example: Self host service is not working
You do have your program running when you try and access it via the browser dont you?
-
Jul 22nd, 2009, 06:21 PM
#6
Thread Starter
Hyperactive Member
Re: WCF example: Self host service is not working
Well, I stopped running the program then access it via the browser.
-
Jul 22nd, 2009, 06:24 PM
#7
Re: WCF example: Self host service is not working
Thats why it isnt working then. The web browser is just a way of connecting to your program, if your program isnt running then there is nothing listening on the port you specified (8080 in your case) so the web browser cant connect to anything. Start your program, then try the web browser again while your program is still open and you should see what you expected to see
-
Jul 24th, 2009, 03:56 AM
#8
Re: WCF example: Self host service is not working
Lol... yes, the service is self-hosted, and is self-hosted as long as the app is running, because it is the host.
Later, you'll probably end up doing these services in IIS, so you don't have to worry too much about the host, but this is to give you an idea of what's going on behind the scenes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|