0
votes

I'm hosting a WCF service (a 1 service function library) on IIS.

I should see(expose) my NotificationsService's function - NotificationAdd - that I created in my service library but I DO NOT. Anyone know why?

I created a 3 project VB.net solution using VS 2013. 1 project the WCF service library 1 project for a IIS host. 1 project for a UI.

The project for the WCF service library. A 1 function service. Called NotificationsServiceLibrary.

The INotificationsService.vb

Imports System
Imports System.ServiceModel
Imports System.ServiceModel.Web

Namespace NotificationsServiceLibrary

    <ServiceContract()>
    Public Interface INotificationsService

        <OperationContract>
        Function NotificationAdd(ByVal pStrUserName As String, ByVal pStrPassword As String, ByVal pStrEmailAddress As String, ByVal pStrSummary As String, ByVal pStrDetail As String, ByVal pStrSource As String, ByVal pStrSourceURL As String, ByVal pDtWhenGenerated As Date, ByVal pDdtSchedule As Date) As NotificationsInfoResult

    End Interface
End Namespace

The NotificationsService.vb

Imports System
Imports System.IO
Imports System.ServiceModel
Imports System.Configuration
Imports System.Xml
Imports System.Data.SqlClient

Namespace NotificationsServiceLibrary

    <ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)>
    Public Class NotificationsService
        Implements INotificationsService

        Public Function NotificationAdd(ByVal pStrUserName As String, ByVal pStrPassword As String, ByVal pStrEmailAddress As String, ByVal pStrSummary As String, ByVal pStrDetail As String, ByVal pStrSource As String, ByVal pStrSourceURL As String, ByVal pDtWhenGenerated As Date, ByVal pDdtSchedule As Date) As NotificationsInfoResult Implements INotificationsService.NotificationAdd

            ' Code here..but removed to keep this short.

            ' Return.
            Return notificationsInfoResult
        End Function
    End Class
End Namespace

The NotificationsServiceData.vb

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Runtime.Serialization

<DataContract()>
Public Class NotificationsInfoResult
    Private _result_code As Integer

    <DataMember()>
    Public Property Result_Code() As Integer
        Get
            Return _result_code
        End Get

        Set(value As Integer)
            _result_code = value
        End Set
    End Property
End Class

Following is the IIS host project which I publish to IIS. Called: NotificationsApiIISHost. In the IIS host project, I added a project reference to the NotificationsServiceLibrary. If I click on it, I can see in the object browser, my 1 function that should be exposed.

The IIS host projects 2 standard default files (which I do NOT USE nor modify) and the web.config that I added to:

IService1.vb

<ServiceContract()>
Public Interface IService1

    <OperationContract()>
    Function GetData(ByVal value As Integer) As String

    <OperationContract()>
    Function GetDataUsingDataContract(ByVal composite As CompositeType) As    CompositeType

    ' TODO: Add your service operations here

End Interface

' Use a data contract as illustrated in the sample below to add composite
types to service operations.

<DataContract()>
Public Class CompositeType

    <DataMember()>
    Public Property BoolValue() As Boolean

   <DataMember()>
    Public Property StringValue() As String
End Class

Service1.svc

Public Class Service1
    Implements IService1

    Public Sub New()
    End Sub

    Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
        Return String.Format("You entered: {0}", value)
    End Function

    Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract
        If composite Is Nothing Then
            Throw New ArgumentNullException("composite")
        End If
        If composite.BoolValue Then
            composite.StringValue &= "Suffix"
        End If
        Return composite
    End Function
End Class

The IIS host's web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="NotificationsServiceLibrary.NotificationsServiceLibrary.NotificationsService">
        <!-- Service Endpoints -->
        <endpoint address="Notifications" binding="wsHttpBinding" contract="NotificationsServiceLibrary.NotificationsServiceLibrary.INotificationsService"     bindingConfiguration="NoSecurityConfig" >
        </endpoint>
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="NoSecurityConfig">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
          <reliableSession enabled="true" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
 </system.webServer>
</configuration>

After I build and publish the host.

Here's the content of the Service1.svc file that was automatically created on IIS.

 <%@ ServiceHost Language="VB" Debug="true"
 Service="NotificationsApiIISHost.Service1" CodeBehind="Service1.svc.vb" %>

I get in VS: ------ Publish started: Project: NotificationsApiIISHost, Configuration: Debug Any CPU ------ Connecting to ftp://dev.notifications.xxxx.net:2121... Transformed Web.config using C:\Dans\Work 2\xxxx\Notifications\Notifications-api\NotificationsApiIISHost\Web.Debug.config into obj\Debug\TransformWebConfig\transformed\Web.config. Copying all files to temporary location below for package/publish: obj\Debug\Package\PackageTmp. Deleting existing files... Publishing folder /... Publishing folder bin... Site was published successfully ftp://dev.notifications.xxxx.net:2121/ Site was published successfully http://dev.notifications.xxx.net/ ========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ========== ========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

and I click on the Service1.svc on the page that is displayed:

dev.notifications.xxxxxx.net - /

10/1/2015 10:49 PM bin

10/1/2015 10:49 PM 120 Service1.svc

10/1/2015 10:49 PM 2900 Web.config

I then click on the http://xxxxx/Service1.svc?singleWsdl and all I see is the default host service functions - GetData and GetDataUsingDataContract. These are placed there when I created the IIS host. There are not even used by me. I should see my function that I created in my service library but I DO NOT.

Here's portion of the wsdl:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="Service1" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost"/>
<xs:element name="GetData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="value" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetDataResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="GetDataResult" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetDataUsingDataContract">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost" minOccurs="0" name="composite" nillable="true" type="q1:CompositeType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetDataUsingDataContractResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost" minOccurs="0" name="GetDataUsingDataContractResult" nillable="true" type="q2:CompositeType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified"
1
I did no understand exactly what you want... do you want to expose the NotificationsService method NotificationAdd? - Ricardo Pontual
@Ricardo. Yes exactly. - user3020047

1 Answers

0
votes

There are a couple of things going on here. First, you've created a WCF Service Library. Secondly, it appears you are trying to host the service library in a WCF Service Application.

First, remove the boilerplate service files. You don't need them and it will only confuse things.

Secondly, add a new file (I generally add a text file and change the extension), named something like "NotificationService.svc".

Open that file in the IDE, and add the following markup:

<%@ ServiceHost Language="VB" Debug="true" Service="NotificationsServiceLibrary.NotificationsService" %>
<%@ Assembly Name="<whatever your service library assembly name is>" %>

When IIS receives the request for the service page, it will use the ServiceHostFactory to create an instance of your service, which is contained in the referenced assembly.