Wrox Programmer Forums
|
BOOK: Professional Visual Basic 2012 and .NET 4.5 Programming
This is the forum to discuss the Wrox book Professional Visual Basic 2012 and .NET 4.5 Programming by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman; ISBN: 978-1-1183-1445-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Visual Basic 2012 and .NET 4.5 Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2014, 03:31 PM
Authorized User
 
Join Date: Jul 2014
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 11, service

I am trying to write from scratch the WCF calculator in chapter 11. I'm on Windows 8.1 and Visual Studio Desktop 2013, Express Edition

Once the service and host projects created, the host (console) seems to work well. A MS DOS screen shows Press <Enter> to close and end the service host

But testing http://localhost:8000/calculator finds nothing, either with the service open or not.

I don't know how to start chasing the cause. Might you please help?

thanks
 
Old July 30th, 2014, 01:09 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

Post your web config, calc code, and is the service in the same solution or project as the consumer code
 
Old July 30th, 2014, 03:32 PM
Authorized User
 
Join Date: Jul 2014
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks,
VS 2013 Express for Web has no Console project template, so I used VS2013Express desktop. No web.config file present, only app.config

Projects are in the same solution (but the goal is to have different assemblies for each tier, and communicate through apache, for instance)

Calc code below...

thanks

here you are Calculator.vb
Imports System.ServiceModel
Imports System.Runtime.Serialization

Public Class Calculator
Implements ICalculator


Public Function Add(a As Integer, b As Integer) As Integer Implements ICalculator.Add
Return (a + b)
End Function

Public Function Divide(a As Integer, b As Integer) As Integer Implements ICalculator.Divide
Return (a - b)
End Function

Public Function Multiply(a As Integer, b As Integer) As Integer Implements ICalculator.Multiply
Return (a * b)
End Function

Public Function Subtract(a As Integer, b As Integer) As Integer Implements ICalculator.Subtract
Return (a / b)
End Function
End Class


and here you are ICalculator.vb

Imports System.Runtime.Serialization
Imports System.ServiceModel

<ServiceContract()>
Public Interface ICalculator
' <OperationContract()>
' Function GetData(ByVal value As Integer) As String
' <OperationContract()>
' Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType
<OperationContract()>
Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
<OperationContract()>
Function Subtract(ByVal a As Integer, ByVal b As Integer) As Integer
<OperationContract()>
Function Multiply(ByVal a As Integer, ByVal b As Integer) As Integer
<OperationContract()>
Function Divide(ByVal a As Integer, ByVal b As Integer) As Integer


End Interface

<DataContract()>
Public Class CompositeType
<DataMember()>
Public Property BoolValue() As Boolean
<DataMember()>
Public Property StringValue() As String

End Class
 
Old July 30th, 2014, 08:33 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

So let my see if i am following you correctly. vs2013 express for web did not have a console app project template so you are using vs2013 for desk top for both the wcf service, service host, and a test project to consume your service am i correct.

Can you post you service host code, your service code looks fine. if you have any configuration in app config post those as well.


until i see your service host code, i am going to go out on a lem here in saying make sure that you are testing the service when the cmd console is up (executing). if the cmd console is not up(not executing) then service host is not listening on the url that you are referrencing in your test.

Also if your service host and test project are in the same sln you will only be able to run one project at a time, break the test application into a seperate sln or open the sln up in 2 differenet instances of vs and run each project in its on vs.


How to test your service host is operating properly with out a test project/consumer. set the service host project as the project to start on start up, then hit the play button. Open you browser and navigate to the url that ther service host is listening to. you should see a service page that allows you to down load the wsdl and show examples of you to use a service client reference.

Last edited by mmorgan30; July 30th, 2014 at 08:42 PM..
 
Old July 30th, 2014, 08:46 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

if your service host code looks something like

Code:

// Create the ServiceHost.
            using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
            {
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                // Open the ServiceHost to start listening for messages. Since
                // no endpoints are explicitly configured, the runtime will create
                // one endpoint per base address for each service contract implemented
                // by the service.
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }

then yes if you are testing the service after you press enter the service host is not running therefore not listening to baseAddress what ever it is.
 
Old August 5th, 2014, 03:48 AM
Authorized User
 
Join Date: Jul 2014
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks

YES, I am using VS2013 express for Desktop for the WCF service, the service host, and a test project (but I haven't yet got to the point to use the test project, just the console and the library)

Service Host code
(although I am unable to guess how to rewrite in VB your C# sentence:
Console.WriteLine("The service is ready at {0}", baseAddress);

Imports System.ServiceModel
Imports System.ServiceModel.Description
Imports System.Windows.Forms

Module ProVB_Host
Public Sub Main()
Using svcHost As New ServiceModel.ServiceHost( _
GetType(WCFCalculatorLibrary.Calculator))

Dim netBind As New NetTcpBinding(SecurityMode.None)

svcHost.AddServiceEndpoint(GetType(WCFCalculatorLi brary.ICalculator),
netBind,
New Uri("net.tcp://localhost.9080/Calculator/"))
Dim smb As New ServiceMetadataBehavior
smb.HttpGetEnabled = True
Try

smb.HttpGetUrl = New Uri("http://localhost.9000/calculator/")
svcHost.Description.Behaviors.Add(smb)
svcHost.Open()
Catch ex As Exception
MessageBox.Show("Error " & Err.Number)
Debug.Print("Error " & Err.Number)
End Try
Console.WriteLine("Press <Enter> to close and end the Service Host, ProVB_Host")

Console.ReadLine()
Console.WriteLine("HOLA")
'Console.WriteLine("The service is ready at {0}", svcHost.BaseAddresses.Item(0).ToString)
Console.ReadLine()
End Using
End Sub
End Module


app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

yes, I'am typing http://localhost:9000/calculator when the console is up and running (waiting for the user to press <Enter> or whatever other key)

Yes, now the two projects are in the same sln



I start xampp, having changed two lines in httpd.conf to listen port 90 instead of 80 (using 80 causes apache doesn't start up)
Listen 90
ServerName localhost:90


In Chrome, typing http://localhost:9000/calculator (or Calculator), with the console up and running, always gives the same message: "webpage not available"
 
Old August 5th, 2014, 09:16 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

1) add service name to the end of your endpoint (in my example it is CalculatoreService, maybe different in your sln )
2) use ':' in url to designate the port not '.'
3) add mex (meta data exporter) to your http get url (wsdl url)

Code:

Module ProVB_Host
    Public Sub Main()

       Using svcHost As New ServiceModel.ServiceHost( GetType(WCFCalculatorLibrary.Calculator))

           Dim netBind As New NetTcpBinding(SecurityMode.None)
           svcHost.AddServiceEndpoint(GetType(WCFCalculatorLi brary.ICalculator),netBind,New Uri("net.tcp://localhost:9080/Calculator/CalculatorService"))
			
            Dim smb As New ServiceMetadataBehavior
	smb.HttpGetEnabled = True
	Try

		smb.HttpGetUrl = New Uri("http://localhost:9000/calculator/mex")
		smb.HttpGetEnabled = true
		svcHost.Description.Behaviors.Add(smb)
		svcHost.Open()
	Catch ex As Exception
		MessageBox.Show("Error " & Err.Number)
		Debug.Print("Error " & Err.Number)
	End Try
			
	Console.WriteLine("The service is ready at {0}", svcHost.BaseAddresses.Item(0).ToString)
	Console.WriteLine("The wsdl is ready at {0}", smb.HttpGetUrl)
	Console.WriteLine("Press <Enter> to close and end the Service Host, ProVB_Host")
      End Using
   End Sub
End Module

 
Old August 6th, 2014, 12:12 PM
Authorized User
 
Join Date: Jul 2014
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, I can see now the wsdl page at http://localhost:9000/Calculator/mex

but I am still not able to find any service when adding service reference (using Discover button, since all projects lie in the same solution

I am doing something wrong, although I don't know what

thanks
 
Old August 6th, 2014, 08:55 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

The self hosted services do not have this capability, this something that is picked up when you have an IIS/web server hosted service using a front end *.svc service interface. This is the method of hosting I prefer. Why reinvent the wheel building your own host when IIS or vs web server can do it for you and it is easy to construct, configure, and install.

To add a serive reference to a test project in the same solution, start the service project in 1 instance of visual studios. While the calc service is running in that instance, add a service reference to your test project in another separate instance of vs(using mex address). You will be able to debug the service using the 1st instance of vs and debug the test project code with the 2nd instance.

Last edited by mmorgan30; August 6th, 2014 at 09:09 PM..
 
Old August 7th, 2014, 04:52 AM
Authorized User
 
Join Date: Jul 2014
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it works, thanks. Not easy without a previous learning process, anyway!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11 Old Sarge BOOK: PHP and MySQL 24-Hour Trainer 3 April 18th, 2013 08:48 AM
chapter 11 cinek BOOK: Beginning iOS 4 Application Development 4 April 30th, 2011 05:13 PM
Chapter 11 thepianoguy BOOK: Professional iPhone and iPad Application Development 1 April 1st, 2011 10:08 AM
Chapter-11 Carlw BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 October 16th, 2008 02:08 PM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.