-
Apr 28th, 2014, 02:05 AM
#1
Thread Starter
Frenzied Member
Wcf hello world
I am trying to get started with WCF. I want to create a hello world web service that runs on ASP.NET development server. I am stuck trying to get the web server to read the service. When I open the website's directory listing in my browser and click on the "HelloWorldService.svc" file, I get the server error:
The type 'MyHelloWorldService.HelloWorldService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I have:
- created my service
- added a website to my project and added a reference to the service
- created a "HelloWorldService.svc" file with the following directive:
<%@ServiceHost Service="MyHelloWorldService.HelloWorldService"%>
This is how my service code files look:
Code:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Namespace MyHelloWorldService
Public Class HelloWorldService
Implements IHelloWorldService
Public Sub New()
End Sub
Public Function GetData(ByVal value As Integer) As String Implements IHelloWorldService.GetData
Return String.Format("You entered: {0}", value)
End Function
End Class
End Namespace
Code:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.ServiceModel
Namespace MyHelloWorldService
<ServiceContract()>
Public Interface IHelloWorldService
<OperationContract()>
Function GetData(ByVal value As Integer) As String
End Interface
End Namespace
-
Apr 28th, 2014, 04:50 AM
#2
Re: Wcf hello world
I am stuck trying to get the web server to read the service.
Is the WCF Service Deployed on the server? If yes, what particular OS did you use?
-
Apr 28th, 2014, 07:29 AM
#3
Thread Starter
Frenzied Member
Re: Wcf hello world
I am running it on Win 7 Pro. I figured it out. I had to tweak some settings in the web application's Web.Config file.
I have some further queries...
I've been following this tutorial:
http://www.codeproject.com/Articles/...F-Service-v4-5
Is WCF that much more complex than ASMX or is this a poor tutorial?
For example, I had to generate the bridging code to instantiate into the client app (via the command prompt and SvcUtil.exe) and it outputted into an App.config file and a C# file which I then had to translate into VB. Is there at least a way of generating this file in VB? Or even better is there a simpler method of generating this file?
Also I tried to return a DataTable to the client console app and it crashed. So I created a function that returned a DataSet and that worked. DataTables weren't returnable from functions in ASMX whereas DataSets were. Is this behaviour similar with WCF web services?
-
Apr 28th, 2014, 11:02 PM
#4
Re: Wcf hello world
Is WCF that much more complex than ASMX or is this a poor tutorial?
Based from the ratings on that post, it's actually 4-5 stars. So, I guess, that post has helped lot's of devs out there. And yes, WCF is a very large area to tackle compared to asmx (web services).
Is there at least a way of generating this file in VB? Or even better is there a simpler method of generating this file?
I believe there's no conversion of a C# WCF Service to VB.NET on the fly. You have to do it manually.
Also I tried to return a DataTable to the client console app and it crashed. So I created a function that returned a DataSet and that worked. DataTables weren't returnable from functions in ASMX whereas DataSets were. Is this behaviour similar with WCF web services?
Actually, you can consume a WCF service in which the return type is Datatable that is defined in the contract.
If your wcf service crashed, then there must be an issue with the retrieved data.
Code:
[ServiceContract]
public interface IDatableDemo
{
[OperationContract]
DataTable GetCustomerDetails();
}
-
Apr 28th, 2014, 11:59 PM
#5
Thread Starter
Frenzied Member
Re: Wcf hello world
Thanks for the info. Appreciated.
That tutorial was good but it seems that I can generate that proxy class by using "Add service reference" rather than generating it via the command prompt and then having to translate it.
The code that I am using to retrieve a dataset uses the GetDataTable procedure and adds the returned table to the DataSet's table collection so they are effectively the same call. This is the code:
GetDataSet works OK but GetDataTable (when called directly from outside) throws the error below beneath the code.
Code:
Public Function GetDataTable() As DataTable Implements IHelloWorldService.GetDataTable
' Create new DataTable instance.
Dim table As New DataTable
' Create four typed columns in the DataTable.
table.Columns.Add("Dosage", GetType(Integer))
table.Columns.Add("Drug", GetType(String))
table.Columns.Add("Patient", GetType(String))
table.Columns.Add("Date", GetType(DateTime))
' Add five rows with those columns filled in the DataTable.
table.Rows.Add(25, "Indocin", "David", DateTime.Now)
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now)
table.Rows.Add(500, "Paracetamol", "Simone", DateTime.Now)
Return table
End Function
Public Function GetDataSet() As DataSet Implements IHelloWorldService.GetDataSet
Dim ds As New DataSet
Dim dt As New DataTable
dt = GetDataTable()
ds.Tables.Add(dt)
Return ds
End Function
An error occurred while receiving the HTTP response to http://localhost:51384/HelloWorldService.svc/uri. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply (TimeSpan timeout)
-
Apr 29th, 2014, 12:45 AM
#6
Re: Wcf hello world
Based from here: maxitemsinobjectgraph, the OP has issue on returning a List<T> about 1,900 items. Setting the maxitemsinobjectgraph was the solution.
I guess in your case, the dataset object contains only one datatable element. Thats why the serialization process succeeded.
If your comfortable with returning just the dataset, then just stick with it rather than further tweaking on the web.config elements.
Last edited by KGComputers; Apr 29th, 2014 at 01:13 AM.
-
Apr 29th, 2014, 01:28 AM
#7
Thread Starter
Frenzied Member
Re: Wcf hello world
Given that a DataSet is just a collection of DataTables then returning a DataSet is no problem. That's how I have always done it with ASMX.
-
Apr 29th, 2014, 01:57 AM
#8
Re: Wcf hello world
Yes, I believe so..
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
|