Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 21st, 2014, 03:31 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old July 30th, 2014, 01:09 AM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #3 (permalink)  
Old July 30th, 2014, 03:32 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #4 (permalink)  
Old July 30th, 2014, 08:33 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #5 (permalink)  
Old July 30th, 2014, 08:46 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #6 (permalink)  
Old August 5th, 2014, 03:48 AM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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"
Reply With Quote
  #7 (permalink)  
Old August 5th, 2014, 09:16 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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

Reply With Quote
  #8 (permalink)  
Old August 6th, 2014, 12:12 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #9 (permalink)  
Old August 6th, 2014, 08:55 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #10 (permalink)  
Old August 7th, 2014, 04:52 AM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05:11 AM



All times are GMT -4. The time now is 01:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.