没有公开vb.net WCF服务库函数 - 它只能看到IIS主机的默认服务(2个函数)

时间:2015-10-02 12:33:51

标签: vb.net wcf

我正在IIS上托管一个WCF服务(一个服务函数库)。

我应该看到(公开)我的NotificationsService函数 - NotificationAdd - 我在服务库中创建但我没有。谁知道为什么?

我使用VS 2013创建了一个3项目VB.net解决方案。 1项目WCF服务库 1个IIS主机项目。 用户界面的1个项目。

WCF服务库的项目。 1功能服务。称为NotificationsServiceLibrary。

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

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

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

以下是我发布到IIS的IIS主机项目。被叫:NotificationsApiIISHost。 在IIS主机项目中,我添加了对NotificationsServiceLibrary的项目引用。 如果我点击它,我可以在对象浏览器中看到我应该公开的1函数。

IIS主机投影2个标准默认文件(我不使用也不修改)和我添加到的web.config:

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

IIS主机的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>

我构建并发布主机后。

以下是在IIS上自动创建的Service1.svc文件的内容。

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

我进入VS:     ------发布开始:项目:NotificationsApiIISHost,配置:调试任何CPU ------     正在连接ftp://dev.notifications.xxxx.net:2121 ...     使用C:\ Dans \ Work 2 \ xxxx \ Notifications \ Notifications-api \ NotificationsApiIISHost \ Web.Debug.config将Web.config转换为obj \ Debug \ TransformWebConfig \ transformed \ Web.config。     将所有文件复制到下面的临时位置以进行包/发布:     OBJ \调试\包\ PackageTmp。     删除现有文件......     发布文件夹/ ...     发布文件夹bin ...     网站已成功发布ftp://dev.notifications.xxxx.net:2121/     网站已成功发布http://dev.notifications.xxx.net/     ==========构建:0成功,0失败,2最新,0跳过==========     ==========发布:1成功,0失败,0跳过==========

然后点击显示的页面上的Service1.svc:

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

然后我点击http://xxxxx/Service1.svc?singleWsdl和 我看到的只是默认的主机服务函数 - GetData和GetDataUsingDataContract。 当我创建IIS主机时,它们放在那里。甚至没有我用过。 我应该看到我在服务库中创建的函数,但我没有。

这是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 个答案:

答案 0 :(得分:0)

这里有几件事情要发生。首先,您已经创建了一个WCF服务库。其次,您似乎正在尝试在WCF服务应用程序中托管服务库。

首先,删除样板服务文件。你不需要它们,它只会混淆事物。

其次,添加一个新文件(我通常添加一个文本文件并更改扩展名),命名为“NotificationService.svc”。

在IDE中打开该文件,并添加以下标记:

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

当IIS收到服务页面请求时,它将使用ServiceHostFactory创建服务实例,该实例包含在引用的程序集中。